mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Don't classify NameRef paths inside attribute TokenTrees
This commit is contained in:
parent
1b9b2d1f40
commit
04f1104179
3 changed files with 22 additions and 14 deletions
|
@ -383,14 +383,17 @@ impl NameRefClass {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(resolved) = sema.resolve_path(&path) {
|
||||
return if path.syntax().ancestors().find_map(ast::Attr::cast).is_some() {
|
||||
let top_path = path.top_path();
|
||||
let is_attribute_path = top_path
|
||||
.syntax()
|
||||
.ancestors()
|
||||
.find_map(ast::Attr::cast)
|
||||
.map(|attr| attr.path().as_ref() == Some(&top_path));
|
||||
return match is_attribute_path {
|
||||
Some(true) => sema.resolve_path(&path).and_then(|resolved| {
|
||||
match resolved {
|
||||
// Don't wanna collide with builtin attributes here like `test` hence guard
|
||||
PathResolution::Def(module @ ModuleDef::Module(_))
|
||||
if path.parent_path().is_some() =>
|
||||
{
|
||||
PathResolution::Def(module @ ModuleDef::Module(_)) if path == top_path => {
|
||||
Some(NameRefClass::Definition(Definition::ModuleDef(module)))
|
||||
}
|
||||
PathResolution::Macro(mac) if mac.kind() == hir::MacroKind::Attr => {
|
||||
|
@ -398,10 +401,10 @@ impl NameRefClass {
|
|||
}
|
||||
_ => None,
|
||||
}
|
||||
} else {
|
||||
Some(NameRefClass::Definition(resolved.into()))
|
||||
};
|
||||
}
|
||||
}),
|
||||
Some(false) => None,
|
||||
None => sema.resolve_path(&path).map(Into::into).map(NameRefClass::Definition),
|
||||
};
|
||||
}
|
||||
|
||||
let extern_crate = ast::ExternCrate::cast(parent)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue