aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/view_crate_graph.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/view_crate_graph.rs')
-rw-r--r--crates/ide/src/view_crate_graph.rs25
1 files changed, 2 insertions, 23 deletions
diff --git a/crates/ide/src/view_crate_graph.rs b/crates/ide/src/view_crate_graph.rs
index 5e4ba881e..df6cc8aed 100644
--- a/crates/ide/src/view_crate_graph.rs
+++ b/crates/ide/src/view_crate_graph.rs
@@ -1,9 +1,4 @@
1use std::{ 1use std::sync::Arc;
2 error::Error,
3 io::{Read, Write},
4 process::{Command, Stdio},
5 sync::Arc,
6};
7 2
8use dot::{Id, LabelText}; 3use dot::{Id, LabelText};
9use ide_db::{ 4use ide_db::{
@@ -38,23 +33,7 @@ pub(crate) fn view_crate_graph(db: &RootDatabase) -> Result<String, String> {
38 33
39 let mut dot = Vec::new(); 34 let mut dot = Vec::new();
40 dot::render(&graph, &mut dot).unwrap(); 35 dot::render(&graph, &mut dot).unwrap();
41 36 Ok(String::from_utf8(dot).unwrap())
42 render_svg(&dot).map_err(|e| e.to_string())
43}
44
45fn render_svg(dot: &[u8]) -> Result<String, Box<dyn Error>> {
46 // We shell out to `dot` to render to SVG, as there does not seem to be a pure-Rust renderer.
47 let child = Command::new("dot")
48 .arg("-Tsvg")
49 .stdin(Stdio::piped())
50 .stdout(Stdio::piped())
51 .spawn()
52 .map_err(|err| format!("failed to spawn `dot`: {}", err))?;
53 child.stdin.unwrap().write_all(&dot)?;
54
55 let mut svg = String::new();
56 child.stdout.unwrap().read_to_string(&mut svg)?;
57 Ok(svg)
58} 37}
59 38
60struct DotCrateGraph { 39struct DotCrateGraph {