diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-22 00:18:19 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-05-22 00:18:19 +0100 |
commit | ae24651e445444d4ed4275a717ac10980f2957a4 (patch) | |
tree | 9ae9115957ab35a3bc7d2d446bce72031328af1a /crates/hir_def/src/item_tree.rs | |
parent | 5b6c0c1af290996a407fb4be51e852317dfab7c2 (diff) | |
parent | 463ecefc64a48d80b2c4591fd4a1b82ae62b2897 (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/hir_def/src/item_tree.rs')
-rw-r--r-- | crates/hir_def/src/item_tree.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index 7440e7d29..528270d49 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs | |||
@@ -1,6 +1,9 @@ | |||
1 | //! A simplified AST that only contains items. | 1 | //! A simplified AST that only contains items. |
2 | 2 | ||
3 | mod lower; | 3 | mod lower; |
4 | mod pretty; | ||
5 | #[cfg(test)] | ||
6 | mod tests; | ||
4 | 7 | ||
5 | use std::{ | 8 | use std::{ |
6 | any::type_name, | 9 | any::type_name, |
@@ -205,6 +208,10 @@ impl ItemTree { | |||
205 | } | 208 | } |
206 | } | 209 | } |
207 | 210 | ||
211 | pub fn pretty_print(&self) -> String { | ||
212 | pretty::print_item_tree(self) | ||
213 | } | ||
214 | |||
208 | fn data(&self) -> &ItemTreeData { | 215 | fn data(&self) -> &ItemTreeData { |
209 | self.data.as_ref().expect("attempted to access data of empty ItemTree") | 216 | self.data.as_ref().expect("attempted to access data of empty ItemTree") |
210 | } | 217 | } |
@@ -776,6 +783,10 @@ impl<T> IdRange<T> { | |||
776 | fn new(range: Range<Idx<T>>) -> Self { | 783 | fn new(range: Range<Idx<T>>) -> Self { |
777 | Self { range: range.start.into_raw().into()..range.end.into_raw().into(), _p: PhantomData } | 784 | Self { range: range.start.into_raw().into()..range.end.into_raw().into(), _p: PhantomData } |
778 | } | 785 | } |
786 | |||
787 | fn is_empty(&self) -> bool { | ||
788 | self.range.is_empty() | ||
789 | } | ||
779 | } | 790 | } |
780 | 791 | ||
781 | impl<T> Iterator for IdRange<T> { | 792 | impl<T> Iterator for IdRange<T> { |