self.with_db(|db| view_hir::view_hir(&db, position))
}
+ /// Renders the crate graph to GraphViz "dot" syntax.
pub fn view_crate_graph(&self) -> Cancelable<Result<String, String>> {
self.with_db(|db| view_crate_graph::view_crate_graph(&db))
}
-use std::{
- error::Error,
- io::{Read, Write},
- process::{Command, Stdio},
- sync::Arc,
-};
+use std::sync::Arc;
use dot::{Id, LabelText};
use ide_db::{
let mut dot = Vec::new();
dot::render(&graph, &mut dot).unwrap();
-
- render_svg(&dot).map_err(|e| e.to_string())
-}
-
-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")
- .arg("-Tsvg")
- .stdin(Stdio::piped())
- .stdout(Stdio::piped())
- .spawn()
- .map_err(|err| format!("failed to spawn `dot`: {}", err))?;
- child.stdin.unwrap().write_all(&dot)?;
-
- let mut svg = String::new();
- child.stdout.unwrap().read_to_string(&mut svg)?;
- Ok(svg)
+ Ok(String::from_utf8(dot).unwrap())
}
struct DotCrateGraph {
//! `ide` crate.
use std::{
- io::Write as _,
- process::{self, Stdio},
+ io::{Read, Write as _},
+ process::{self, Command, Stdio},
};
use ide::{
pub(crate) fn handle_view_crate_graph(snap: GlobalStateSnapshot, (): ()) -> Result<String> {
let _p = profile::span("handle_view_crate_graph");
- let res = snap.analysis.view_crate_graph()??;
- Ok(res)
+ let dot = snap.analysis.view_crate_graph()??;
+
+ // 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")
+ .arg("-Tsvg")
+ .stdin(Stdio::piped())
+ .stdout(Stdio::piped())
+ .spawn()
+ .map_err(|err| format!("failed to spawn `dot`: {}", err))?;
+ child.stdin.unwrap().write_all(dot.as_bytes())?;
+
+ let mut svg = String::new();
+ child.stdout.unwrap().read_to_string(&mut svg)?;
+ Ok(svg)
}
pub(crate) fn handle_expand_macro(