mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Merge #5396
5396: Cap macro expansion depth for IDE features r=matklad a=matklad closes #4453 bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
e30d39d502
2 changed files with 20 additions and 1 deletions
|
@ -352,7 +352,7 @@ impl SourceAnalyzer {
|
|||
let macro_call_id = macro_call.as_call_id(db.upcast(), krate, |path| {
|
||||
self.resolver.resolve_path_as_macro(db.upcast(), &path)
|
||||
})?;
|
||||
Some(macro_call_id.as_file())
|
||||
Some(macro_call_id.as_file()).filter(|it| it.expansion_level(db.upcast()) < 64)
|
||||
}
|
||||
|
||||
pub(crate) fn resolve_variant(
|
||||
|
|
|
@ -88,6 +88,25 @@ impl HirFileId {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn expansion_level(self, db: &dyn db::AstDatabase) -> u32 {
|
||||
let mut level = 0;
|
||||
let mut curr = self;
|
||||
while let HirFileIdRepr::MacroFile(macro_file) = curr.0 {
|
||||
level += 1;
|
||||
curr = match macro_file.macro_call_id {
|
||||
MacroCallId::LazyMacro(id) => {
|
||||
let loc = db.lookup_intern_macro(id);
|
||||
loc.kind.file_id()
|
||||
}
|
||||
MacroCallId::EagerMacro(id) => {
|
||||
let loc = db.lookup_intern_eager_expansion(id);
|
||||
loc.file_id
|
||||
}
|
||||
};
|
||||
}
|
||||
level
|
||||
}
|
||||
|
||||
/// If this is a macro call, returns the syntax node of the call.
|
||||
pub fn call_node(self, db: &dyn db::AstDatabase) -> Option<InFile<SyntaxNode>> {
|
||||
match self.0 {
|
||||
|
|
Loading…
Reference in a new issue