diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide/src/lib.rs | 5 | ||||
-rw-r--r-- | crates/ide/src/view_item_tree.rs | 16 | ||||
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 10 | ||||
-rw-r--r-- | crates/rust-analyzer/src/lsp_ext.rs | 14 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 1 |
5 files changed, 46 insertions, 0 deletions
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index f4b90db3a..ff2a54117 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs | |||
@@ -50,6 +50,7 @@ mod typing; | |||
50 | mod markdown_remove; | 50 | mod markdown_remove; |
51 | mod doc_links; | 51 | mod doc_links; |
52 | mod view_crate_graph; | 52 | mod view_crate_graph; |
53 | mod view_item_tree; | ||
53 | 54 | ||
54 | use std::sync::Arc; | 55 | use std::sync::Arc; |
55 | 56 | ||
@@ -288,6 +289,10 @@ impl Analysis { | |||
288 | self.with_db(|db| view_hir::view_hir(&db, position)) | 289 | self.with_db(|db| view_hir::view_hir(&db, position)) |
289 | } | 290 | } |
290 | 291 | ||
292 | pub fn view_item_tree(&self, file_id: FileId) -> Cancelable<String> { | ||
293 | self.with_db(|db| view_item_tree::view_item_tree(&db, file_id)) | ||
294 | } | ||
295 | |||
291 | /// Renders the crate graph to GraphViz "dot" syntax. | 296 | /// Renders the crate graph to GraphViz "dot" syntax. |
292 | pub fn view_crate_graph(&self) -> Cancelable<Result<String, String>> { | 297 | pub fn view_crate_graph(&self) -> Cancelable<Result<String, String>> { |
293 | self.with_db(|db| view_crate_graph::view_crate_graph(&db)) | 298 | self.with_db(|db| view_crate_graph::view_crate_graph(&db)) |
diff --git a/crates/ide/src/view_item_tree.rs b/crates/ide/src/view_item_tree.rs new file mode 100644 index 000000000..3dc03085d --- /dev/null +++ b/crates/ide/src/view_item_tree.rs | |||
@@ -0,0 +1,16 @@ | |||
1 | use hir::db::DefDatabase; | ||
2 | use ide_db::base_db::FileId; | ||
3 | use ide_db::RootDatabase; | ||
4 | |||
5 | // Feature: Debug ItemTree | ||
6 | // | ||
7 | // Displays the ItemTree of the currently open file, for debugging. | ||
8 | // | ||
9 | // |=== | ||
10 | // | Editor | Action Name | ||
11 | // | ||
12 | // | VS Code | **Rust Analyzer: Debug ItemTree** | ||
13 | // |=== | ||
14 | pub(crate) fn view_item_tree(db: &RootDatabase, file_id: FileId) -> String { | ||
15 | db.file_item_tree(file_id.into()).pretty_print() | ||
16 | } | ||
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 51041d7a0..aa12fd94b 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs | |||
@@ -117,6 +117,16 @@ pub(crate) fn handle_view_hir( | |||
117 | Ok(res) | 117 | Ok(res) |
118 | } | 118 | } |
119 | 119 | ||
120 | pub(crate) fn handle_view_item_tree( | ||
121 | snap: GlobalStateSnapshot, | ||
122 | params: lsp_ext::ViewItemTreeParams, | ||
123 | ) -> Result<String> { | ||
124 | let _p = profile::span("handle_view_item_tree"); | ||
125 | let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; | ||
126 | let res = snap.analysis.view_item_tree(file_id)?; | ||
127 | Ok(res) | ||
128 | } | ||
129 | |||
120 | pub(crate) fn handle_view_crate_graph(snap: GlobalStateSnapshot, (): ()) -> Result<String> { | 130 | pub(crate) fn handle_view_crate_graph(snap: GlobalStateSnapshot, (): ()) -> Result<String> { |
121 | let _p = profile::span("handle_view_crate_graph"); | 131 | let _p = profile::span("handle_view_crate_graph"); |
122 | let dot = snap.analysis.view_crate_graph()??; | 132 | let dot = snap.analysis.view_crate_graph()??; |
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs index 34b53a7a8..905048793 100644 --- a/crates/rust-analyzer/src/lsp_ext.rs +++ b/crates/rust-analyzer/src/lsp_ext.rs | |||
@@ -70,6 +70,20 @@ impl Request for ViewCrateGraph { | |||
70 | const METHOD: &'static str = "rust-analyzer/viewCrateGraph"; | 70 | const METHOD: &'static str = "rust-analyzer/viewCrateGraph"; |
71 | } | 71 | } |
72 | 72 | ||
73 | #[derive(Deserialize, Serialize, Debug)] | ||
74 | #[serde(rename_all = "camelCase")] | ||
75 | pub struct ViewItemTreeParams { | ||
76 | pub text_document: TextDocumentIdentifier, | ||
77 | } | ||
78 | |||
79 | pub enum ViewItemTree {} | ||
80 | |||
81 | impl Request for ViewItemTree { | ||
82 | type Params = ViewItemTreeParams; | ||
83 | type Result = String; | ||
84 | const METHOD: &'static str = "rust-analyzer/viewItemTree"; | ||
85 | } | ||
86 | |||
73 | pub enum ExpandMacro {} | 87 | pub enum ExpandMacro {} |
74 | 88 | ||
75 | impl Request for ExpandMacro { | 89 | impl Request for ExpandMacro { |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index 4e0791611..f837b89dd 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -514,6 +514,7 @@ impl GlobalState { | |||
514 | .on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree) | 514 | .on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree) |
515 | .on::<lsp_ext::ViewHir>(handlers::handle_view_hir) | 515 | .on::<lsp_ext::ViewHir>(handlers::handle_view_hir) |
516 | .on::<lsp_ext::ViewCrateGraph>(handlers::handle_view_crate_graph) | 516 | .on::<lsp_ext::ViewCrateGraph>(handlers::handle_view_crate_graph) |
517 | .on::<lsp_ext::ViewItemTree>(handlers::handle_view_item_tree) | ||
517 | .on::<lsp_ext::ExpandMacro>(handlers::handle_expand_macro) | 518 | .on::<lsp_ext::ExpandMacro>(handlers::handle_expand_macro) |
518 | .on::<lsp_ext::ParentModule>(handlers::handle_parent_module) | 519 | .on::<lsp_ext::ParentModule>(handlers::handle_parent_module) |
519 | .on::<lsp_ext::Runnables>(handlers::handle_runnables) | 520 | .on::<lsp_ext::Runnables>(handlers::handle_runnables) |