aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-22 00:18:19 +0100
committerGitHub <[email protected]>2021-05-22 00:18:19 +0100
commitae24651e445444d4ed4275a717ac10980f2957a4 (patch)
tree9ae9115957ab35a3bc7d2d446bce72031328af1a /crates/ide
parent5b6c0c1af290996a407fb4be51e852317dfab7c2 (diff)
parent463ecefc64a48d80b2c4591fd4a1b82ae62b2897 (diff)
Merge #8916
8916: ItemTree pretty-printing r=jonas-schievink a=jonas-schievink This adds a printer for `ItemTree` contents, and a few tests to ensure that `ItemTree` lowering works like we expect it to. It also adds a new "Debug ItemTree" command that can be used to see the `ItemTree` of the currently open file. The pretty-printed output is usually close enough to Rust syntax that we can even use Rust syntax highlighting. This is similar to the old `ItemTree` tests we had, but produces significantly more readable output, so these should actually carry their weight. Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/lib.rs5
-rw-r--r--crates/ide/src/view_item_tree.rs16
2 files changed, 21 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;
50mod markdown_remove; 50mod markdown_remove;
51mod doc_links; 51mod doc_links;
52mod view_crate_graph; 52mod view_crate_graph;
53mod view_item_tree;
53 54
54use std::sync::Arc; 55use 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 @@
1use hir::db::DefDatabase;
2use ide_db::base_db::FileId;
3use 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// |===
14pub(crate) fn view_item_tree(db: &RootDatabase, file_id: FileId) -> String {
15 db.file_item_tree(file_id.into()).pretty_print()
16}