-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
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. |
There was a problem hiding this comment.
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.
Can we limit this to workspace crates by default? should be more useful that way.
Hey, I have a new idea for a code complexity metric! |
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. |
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+ |
|
||
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") |
There was a problem hiding this comment.
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.
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>
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:Unfortunately, on rust-analyzer itself (and most medium-sized dependency graphs),
dot
runs for around a minute and then produces this mess: