mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Merge #8807
8807: internal: Move `dot` invocation to rust-analyzer crate r=jonas-schievink a=jonas-schievink Addresses https://github.com/rust-analyzer/rust-analyzer/pull/8801#discussion_r630570615 bors r+ Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
commit
acde43f7c9
@ -288,6 +288,7 @@ impl Analysis {
|
|||||||
self.with_db(|db| view_hir::view_hir(&db, position))
|
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>> {
|
pub fn view_crate_graph(&self) -> Cancelable<Result<String, String>> {
|
||||||
self.with_db(|db| view_crate_graph::view_crate_graph(&db))
|
self.with_db(|db| view_crate_graph::view_crate_graph(&db))
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
use std::{
|
use std::sync::Arc;
|
||||||
error::Error,
|
|
||||||
io::{Read, Write},
|
|
||||||
process::{Command, Stdio},
|
|
||||||
sync::Arc,
|
|
||||||
};
|
|
||||||
|
|
||||||
use dot::{Id, LabelText};
|
use dot::{Id, LabelText};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
@ -38,23 +33,7 @@ pub(crate) fn view_crate_graph(db: &RootDatabase) -> Result<String, String> {
|
|||||||
|
|
||||||
let mut dot = Vec::new();
|
let mut dot = Vec::new();
|
||||||
dot::render(&graph, &mut dot).unwrap();
|
dot::render(&graph, &mut dot).unwrap();
|
||||||
|
Ok(String::from_utf8(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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DotCrateGraph {
|
struct DotCrateGraph {
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
//! `ide` crate.
|
//! `ide` crate.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
io::Write as _,
|
io::{Read, Write as _},
|
||||||
process::{self, Stdio},
|
process::{self, Command, Stdio},
|
||||||
};
|
};
|
||||||
|
|
||||||
use ide::{
|
use ide::{
|
||||||
@ -119,8 +119,20 @@ pub(crate) fn handle_view_hir(
|
|||||||
|
|
||||||
pub(crate) fn handle_view_crate_graph(snap: GlobalStateSnapshot, (): ()) -> Result<String> {
|
pub(crate) fn handle_view_crate_graph(snap: GlobalStateSnapshot, (): ()) -> Result<String> {
|
||||||
let _p = profile::span("handle_view_crate_graph");
|
let _p = profile::span("handle_view_crate_graph");
|
||||||
let res = snap.analysis.view_crate_graph()??;
|
let dot = snap.analysis.view_crate_graph()??;
|
||||||
Ok(res)
|
|
||||||
|
// 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(
|
pub(crate) fn handle_expand_macro(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user