diff options
author | Jonas Schievink <[email protected]> | 2021-05-11 23:14:59 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2021-05-11 23:14:59 +0100 |
commit | 23cd6d0d562552886c4b170327b22fb226fb9cb1 (patch) | |
tree | 852aceb23512b159e24316f58ef32c2f09ed8eb7 /crates/rust-analyzer/src/handlers.rs | |
parent | a328a6bc75e3832930bd22fb644a994dcd3d93ff (diff) |
Move `dot` invocation to rust-analyzer crate
Diffstat (limited to 'crates/rust-analyzer/src/handlers.rs')
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index dafbab6d0..551013aa9 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs | |||
@@ -3,8 +3,8 @@ | |||
3 | //! `ide` crate. | 3 | //! `ide` crate. |
4 | 4 | ||
5 | use std::{ | 5 | use std::{ |
6 | io::Write as _, | 6 | io::{Read, Write as _}, |
7 | process::{self, Stdio}, | 7 | process::{self, Command, Stdio}, |
8 | }; | 8 | }; |
9 | 9 | ||
10 | use ide::{ | 10 | use ide::{ |
@@ -119,8 +119,20 @@ pub(crate) fn handle_view_hir( | |||
119 | 119 | ||
120 | pub(crate) fn handle_view_crate_graph(snap: GlobalStateSnapshot, (): ()) -> Result<String> { | 120 | pub(crate) fn handle_view_crate_graph(snap: GlobalStateSnapshot, (): ()) -> Result<String> { |
121 | let _p = profile::span("handle_view_crate_graph"); | 121 | let _p = profile::span("handle_view_crate_graph"); |
122 | let res = snap.analysis.view_crate_graph()??; | 122 | let dot = snap.analysis.view_crate_graph()??; |
123 | Ok(res) | 123 | |
124 | // We shell out to `dot` to render to SVG, as there does not seem to be a pure-Rust renderer. | ||
125 | let child = Command::new("dot") | ||
126 | .arg("-Tsvg") | ||
127 | .stdin(Stdio::piped()) | ||
128 | .stdout(Stdio::piped()) | ||
129 | .spawn() | ||
130 | .map_err(|err| format!("failed to spawn `dot`: {}", err))?; | ||
131 | child.stdin.unwrap().write_all(dot.as_bytes())?; | ||
132 | |||
133 | let mut svg = String::new(); | ||
134 | child.stdout.unwrap().read_to_string(&mut svg)?; | ||
135 | Ok(svg) | ||
124 | } | 136 | } |
125 | 137 | ||
126 | pub(crate) fn handle_expand_macro( | 138 | pub(crate) fn handle_expand_macro( |