diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 336ef9a0315..4fb049ce9ae 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -299,8 +299,8 @@ impl Analysis { } /// Renders the crate graph to GraphViz "dot" syntax. - pub fn view_crate_graph(&self) -> Cancellable> { - self.with_db(|db| view_crate_graph::view_crate_graph(db)) + pub fn view_crate_graph(&self, full: bool) -> Cancellable> { + self.with_db(|db| view_crate_graph::view_crate_graph(db, full)) } pub fn expand_macro(&self, position: FilePosition) -> Cancellable> { diff --git a/crates/ide/src/view_crate_graph.rs b/crates/ide/src/view_crate_graph.rs index df6cc8aedde..30ec67b0696 100644 --- a/crates/ide/src/view_crate_graph.rs +++ b/crates/ide/src/view_crate_graph.rs @@ -19,14 +19,18 @@ use rustc_hash::FxHashSet; // // | VS Code | **Rust Analyzer: View Crate Graph** // |=== -pub(crate) fn view_crate_graph(db: &RootDatabase) -> Result { +pub(crate) fn view_crate_graph(db: &RootDatabase, full: bool) -> Result { let crate_graph = db.crate_graph(); let crates_to_render = crate_graph .iter() .filter(|krate| { - // Only render workspace crates - let root_id = db.file_source_root(crate_graph[*krate].root_file_id); - !db.source_root(root_id).is_library + if full { + true + } else { + // Only render workspace crates + let root_id = db.file_source_root(crate_graph[*krate].root_file_id); + !db.source_root(root_id).is_library + } }) .collect(); let graph = DotCrateGraph { graph: crate_graph, crates_to_render }; diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index f7fa8f294c8..b06bfe49d63 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -38,7 +38,7 @@ use crate::{ from_proto, global_state::{GlobalState, GlobalStateSnapshot}, line_index::LineEndings, - lsp_ext::{self, InlayHint, InlayHintsParams, WorkspaceSymbolParams}, + lsp_ext::{self, InlayHint, InlayHintsParams, ViewCrateGraphParams, WorkspaceSymbolParams}, lsp_utils::all_edits_are_disjoint, to_proto, LspError, Result, }; @@ -131,9 +131,12 @@ pub(crate) fn handle_view_item_tree( Ok(res) } -pub(crate) fn handle_view_crate_graph(snap: GlobalStateSnapshot, (): ()) -> Result { +pub(crate) fn handle_view_crate_graph( + snap: GlobalStateSnapshot, + params: ViewCrateGraphParams, +) -> Result { let _p = profile::span("handle_view_crate_graph"); - let dot = snap.analysis.view_crate_graph()??; + let dot = snap.analysis.view_crate_graph(params.full)??; // 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") diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index 90504879304..07497e4c44a 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs @@ -62,10 +62,17 @@ impl Request for ViewHir { const METHOD: &'static str = "rust-analyzer/viewHir"; } +#[derive(Deserialize, Serialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct ViewCrateGraphParams { + /// Include *all* crates, not just crates in the workspace. + pub full: bool, +} + pub enum ViewCrateGraph {} impl Request for ViewCrateGraph { - type Params = (); + type Params = ViewCrateGraphParams; type Result = String; const METHOD: &'static str = "rust-analyzer/viewCrateGraph"; } diff --git a/docs/dev/lsp-extensions.md b/docs/dev/lsp-extensions.md index 11a3dd04e8e..8fb1da351f7 100644 --- a/docs/dev/lsp-extensions.md +++ b/docs/dev/lsp-extensions.md @@ -1,5 +1,5 @@