Don't classify NameRef paths inside attribute TokenTrees
This commit is contained in:
parent
1b9b2d1f40
commit
04f1104179
@ -1,5 +1,3 @@
|
||||
use std::iter::successors;
|
||||
|
||||
use syntax::{ast, AstNode, T};
|
||||
|
||||
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||
@ -18,9 +16,8 @@
|
||||
pub(crate) fn split_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
|
||||
let colon_colon = ctx.find_token_syntax_at_offset(T![::])?;
|
||||
let path = ast::Path::cast(colon_colon.parent()?)?.qualifier()?;
|
||||
let top_path = successors(Some(path.clone()), |it| it.parent_path()).last()?;
|
||||
|
||||
let use_tree = top_path.syntax().ancestors().find_map(ast::UseTree::cast)?;
|
||||
let use_tree = path.top_path().syntax().ancestors().find_map(ast::UseTree::cast)?;
|
||||
|
||||
let new_tree = use_tree.split_prefix(&path);
|
||||
if new_tree == use_tree {
|
||||
|
@ -383,14 +383,17 @@ pub fn classify(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ pub fn classify(
|
||||
}
|
||||
_ => 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)?;
|
||||
|
@ -336,6 +336,14 @@ pub fn segments(&self) -> impl Iterator<Item = ast::PathSegment> + Clone {
|
||||
pub fn qualifiers(&self) -> impl Iterator<Item = ast::Path> + Clone {
|
||||
successors(self.qualifier(), |p| p.qualifier())
|
||||
}
|
||||
|
||||
pub fn top_path(&self) -> ast::Path {
|
||||
let mut this = self.clone();
|
||||
while let Some(path) = this.parent_path() {
|
||||
this = path;
|
||||
}
|
||||
this
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::Use {
|
||||
|
Loading…
Reference in New Issue
Block a user