diff options
author | Aleksey Kladov <[email protected]> | 2020-07-15 16:18:19 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-07-15 16:18:19 +0100 |
commit | 6b9c72567363edcff5f4e703646b7246fdf5c671 (patch) | |
tree | f3b2cc18538eb70dfe1b7ccca20873b5ea11ea4e /crates/ra_hir_expand | |
parent | 0908318171b78254f72ab3dc3bc6385f8e00ffd8 (diff) |
Cap macro expansion depth for IDE features
closes #4453
Diffstat (limited to 'crates/ra_hir_expand')
-rw-r--r-- | crates/ra_hir_expand/src/lib.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs index 5eac2605b..1cf6c1ba9 100644 --- a/crates/ra_hir_expand/src/lib.rs +++ b/crates/ra_hir_expand/src/lib.rs | |||
@@ -88,6 +88,25 @@ impl HirFileId { | |||
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | pub fn expansion_level(self, db: &dyn db::AstDatabase) -> u32 { | ||
92 | let mut level = 0; | ||
93 | let mut curr = self; | ||
94 | while let HirFileIdRepr::MacroFile(macro_file) = curr.0 { | ||
95 | level += 1; | ||
96 | curr = match macro_file.macro_call_id { | ||
97 | MacroCallId::LazyMacro(id) => { | ||
98 | let loc = db.lookup_intern_macro(id); | ||
99 | loc.kind.file_id() | ||
100 | } | ||
101 | MacroCallId::EagerMacro(id) => { | ||
102 | let loc = db.lookup_intern_eager_expansion(id); | ||
103 | loc.file_id | ||
104 | } | ||
105 | }; | ||
106 | } | ||
107 | level | ||
108 | } | ||
109 | |||
91 | /// If this is a macro call, returns the syntax node of the call. | 110 | /// If this is a macro call, returns the syntax node of the call. |
92 | pub fn call_node(self, db: &dyn db::AstDatabase) -> Option<InFile<SyntaxNode>> { | 111 | pub fn call_node(self, db: &dyn db::AstDatabase) -> Option<InFile<SyntaxNode>> { |
93 | match self.0 { | 112 | match self.0 { |