Skip to content

Commit 6c80c42

Browse files
bors[bot]p32blo
andauthored
Merge #9828
9828: Remove dependency on the system graphviz when rendering crate graph r=lnicola a=p32blo This PR removes the need for having `graphviz` installed on the user system by using the `d3-graphviz` npm package. The responsibility of rendering the svg output is moved to the extension while the rust side only handles the generation of the dot file. This change also brings the following additional features: - Allow zooming the view - Ctrl+click to reset the zoom - Adjust the color scheme to dark themes - Works on any platform without installing graphviz locally --- I’m not sure if this fits what you had in mind for the crates graph feature but I decided to submit it anyway to see if this is useful to anyone else. A potential downside might be that it increases the extension size ( haven’t checked) but this feature already required the installation of graphviz on the user side, so the cost is just moved explicitly to the extension. Feel free to make any suggestion or comments. Co-authored-by: André Oliveira <p32blo@gmail.com>
2 parents c943057 + 25e1ca3 commit 6c80c42

File tree

6 files changed

+1025
-19
lines changed

6 files changed

+1025
-19
lines changed

crates/rust-analyzer/src/handlers.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
//! `ide` crate.
44
55
use std::{
6-
io::{Read, Write as _},
7-
process::{self, Command, Stdio},
6+
io::Write as _,
7+
process::{self, Stdio},
88
};
99

1010
use ide::{
@@ -132,19 +132,7 @@ pub(crate) fn handle_view_crate_graph(
132132
) -> Result<String> {
133133
let _p = profile::span("handle_view_crate_graph");
134134
let dot = snap.analysis.view_crate_graph(params.full)??;
135-
136-
// We shell out to `dot` to render to SVG, as there does not seem to be a pure-Rust renderer.
137-
let child = Command::new("dot")
138-
.arg("-Tsvg")
139-
.stdin(Stdio::piped())
140-
.stdout(Stdio::piped())
141-
.spawn()
142-
.map_err(|err| format!("failed to spawn `dot`: {}", err))?;
143-
child.stdin.unwrap().write_all(dot.as_bytes())?;
144-
145-
let mut svg = String::new();
146-
child.stdout.unwrap().read_to_string(&mut svg)?;
147-
Ok(svg)
135+
Ok(dot)
148136
}
149137

150138
pub(crate) fn handle_expand_macro(

editors/code/.vscodeignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
!out
44
out/**
55
!out/src
6+
!node_modules/d3/dist/d3.min.js
7+
!node_modules/@hpcc-js/wasm/dist/index.min.js
8+
!node_modules/@hpcc-js/wasm/dist/graphvizlib.wasm
9+
!node_modules/d3-graphviz/build/d3-graphviz.min.js
610
!package.json
711
!package-lock.json
812
!ra_syntax_tree.tmGrammar.json

0 commit comments

Comments
 (0)