Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow viewing the crate graph in a webview #8801

Merged
merged 6 commits into from
May 11, 2021
Merged

feat: Allow viewing the crate graph in a webview #8801

merged 6 commits into from
May 11, 2021

Conversation

jonas-schievink
Copy link
Contributor

@jonas-schievink jonas-schievink commented May 11, 2021

This uses dot to render the crate graph as an SVD file, and displays it in a VS Code panel. For simple crate graphs, it works quite well:

screenshot-2021-05-11-16:19:32

Unfortunately, on rust-analyzer itself (and most medium-sized dependency graphs), dot runs for around a minute and then produces this mess:

screenshot-2021-05-11-16:41:37

jonas-schievink and others added 2 commits May 11, 2021 16:42
Co-authored-by: bjorn3 <bjorn3@users.noreply.github.com>
}

fn render_svg(dot: &[u8]) -> Result<String, Box<dyn Error>> {
// We shell out to `dot` to render to SVG, as there does not seem to be a pure-Rust renderer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to consider investigating the different layout options. For example dot -Kneato. (all options for dot -K are: circo dot fdp neato nop nop1 nop2 osage patchwork sfdp twopi) Be aware that some option are extremely slow for large graphs though. You can also use options like -Gnslimit=1, -Glheight=1000 and -Gmaxiter=1 to increase the svg height for clearer graphs or reduce the amount of effort used to layout, increasing speed.

@matklad
Copy link
Member

matklad commented May 11, 2021

Can we limit this to workspace crates by default? should be more useful that way.

dot runs for around a minute

Hey, I have a new idea for a code complexity metric!

@bjorn3
Copy link
Member

bjorn3 commented May 11, 2021

Did you know about mermaid.js? I don't know how the quality and speed of lay-outing compares with graphviz, but it doesn't require an external tool to be installed as it can run directly in the webview.

@jonas-schievink
Copy link
Contributor Author

The reduced version looks "good enough" now. It looks like all tests/binaries share the name with the main library crate though, so that's somewhat confusing.

bors r+

@bors
Copy link
Contributor

bors bot commented May 11, 2021

@bors bors bot merged commit e290891 into rust-lang:master May 11, 2021
@jonas-schievink jonas-schievink deleted the view-crate-graph branch May 11, 2021 18:14

fn render_svg(dot: &[u8]) -> Result<String, Box<dyn Error>> {
// We shell out to `dot` to render to SVG, as there does not seem to be a pure-Rust renderer.
let child = Command::new("dot")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the layering is slightly off here, we generally don’t do IO, including IPC, in the ide layer and below. I think it’d be more orthogonal to return a string in a .dot format from here, and let the client (rust-analyzer binary) render it to svg.

bors bot added a commit that referenced this pull request May 11, 2021
8807: internal: Move `dot` invocation to rust-analyzer crate r=jonas-schievink a=jonas-schievink

Addresses #8801 (comment)

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants