aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-05-11 23:14:59 +0100
committerJonas Schievink <[email protected]>2021-05-11 23:14:59 +0100
commit23cd6d0d562552886c4b170327b22fb226fb9cb1 (patch)
tree852aceb23512b159e24316f58ef32c2f09ed8eb7 /crates/ide
parenta328a6bc75e3832930bd22fb644a994dcd3d93ff (diff)
Move `dot` invocation to rust-analyzer crate
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/lib.rs1
-rw-r--r--crates/ide/src/view_crate_graph.rs25
2 files changed, 3 insertions, 23 deletions
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs
index 34360501a..db08547d1 100644
--- a/crates/ide/src/lib.rs
+++ b/crates/ide/src/lib.rs
@@ -288,6 +288,7 @@ impl Analysis {
288 self.with_db(|db| view_hir::view_hir(&db, position)) 288 self.with_db(|db| view_hir::view_hir(&db, position))
289 } 289 }
290 290
291 /// Renders the crate graph to GraphViz "dot" syntax.
291 pub fn view_crate_graph(&self) -> Cancelable<Result<String, String>> { 292 pub fn view_crate_graph(&self) -> Cancelable<Result<String, String>> {
292 self.with_db(|db| view_crate_graph::view_crate_graph(&db)) 293 self.with_db(|db| view_crate_graph::view_crate_graph(&db))
293 } 294 }
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 {