mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Handle self/super/crate in PathSegment as NameRef
This commit is contained in:
parent
0c58aa9dc0
commit
cb863390f2
42 changed files with 258 additions and 254 deletions
|
@ -226,35 +226,16 @@ pub(super) fn element(
|
|||
T![unsafe] => h | HlMod::Unsafe,
|
||||
T![true] | T![false] => HlTag::BoolLiteral.into(),
|
||||
T![self] => {
|
||||
let self_param_is_mut = element
|
||||
.parent()
|
||||
.and_then(ast::SelfParam::cast)
|
||||
.and_then(|p| p.mut_token())
|
||||
.is_some();
|
||||
let self_path = &element
|
||||
.parent()
|
||||
.as_ref()
|
||||
.and_then(SyntaxNode::parent)
|
||||
.and_then(ast::Path::cast)
|
||||
.and_then(|p| sema.resolve_path(&p));
|
||||
let mut h = HlTag::Symbol(SymbolKind::SelfParam).into();
|
||||
if self_param_is_mut
|
||||
|| matches!(self_path,
|
||||
Some(hir::PathResolution::Local(local))
|
||||
if local.is_self(db)
|
||||
&& (local.is_mut(db) || local.ty(db).is_mutable_reference())
|
||||
)
|
||||
let self_param = element.parent().and_then(ast::SelfParam::cast);
|
||||
if let Some(NameClass::Definition(def)) = self_param
|
||||
.and_then(|self_param| NameClass::classify_self_param(sema, &self_param))
|
||||
{
|
||||
h |= HlMod::Mutable
|
||||
highlight_def(db, def) | HlMod::Definition
|
||||
} else if element.ancestors().any(|it| it.kind() == USE_TREE) {
|
||||
HlTag::Symbol(SymbolKind::SelfParam).into()
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
|
||||
if let Some(hir::PathResolution::Local(local)) = self_path {
|
||||
if is_consumed_lvalue(element, &local, db) {
|
||||
h |= HlMod::Consuming;
|
||||
}
|
||||
}
|
||||
|
||||
h
|
||||
}
|
||||
T![ref] => element
|
||||
.parent()
|
||||
|
@ -345,7 +326,9 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
|
|||
hir::GenericParam::LifetimeParam(_) => HlTag::Symbol(SymbolKind::LifetimeParam),
|
||||
},
|
||||
Definition::Local(local) => {
|
||||
let tag = if local.is_param(db) {
|
||||
let tag = if local.is_self(db) {
|
||||
HlTag::Symbol(SymbolKind::SelfParam)
|
||||
} else if local.is_param(db) {
|
||||
HlTag::Symbol(SymbolKind::ValueParam)
|
||||
} else {
|
||||
HlTag::Symbol(SymbolKind::Local)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue