diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-15 16:19:07 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-15 16:19:07 +0100 |
commit | e30d39d502e485648116d8b608236487e5ebe3df (patch) | |
tree | 07d8579a85e7fb5eb7875f6e0962dd70bb15f559 /crates/ra_hir_expand/src/lib.rs | |
parent | 2a01fe7d99376053b97aba9105dc7d9cf0c0641d (diff) | |
parent | 6b9c72567363edcff5f4e703646b7246fdf5c671 (diff) |
Merge #5396
5396: Cap macro expansion depth for IDE features r=matklad a=matklad
closes #4453
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_expand/src/lib.rs')
-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 { |