diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-15 18:40:47 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-15 18:40:47 +0000 |
commit | 8a869e870ac6328967fb120a0ebe44a9c900eaf0 (patch) | |
tree | f4ad40fc09483af3e9fea77d4b4156130539a70c /crates/ide/src/syntax_highlighting/highlight.rs | |
parent | 148e3d0f6a28f57565538dca7d9c0f5f726a5908 (diff) | |
parent | cb863390f23bc2eac6561d55def9bd3ba54605fc (diff) |
Merge #7288
7288: Handle self/super/crate in PathSegment as NameRef r=matklad a=Veykril
Wrapping self/super/crate in NameRef as per https://github.com/rust-analyzer/rust-analyzer/pull/7261#issuecomment-760023172
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide/src/syntax_highlighting/highlight.rs')
-rw-r--r-- | crates/ide/src/syntax_highlighting/highlight.rs | 39 |
1 files changed, 11 insertions, 28 deletions
diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 34bae49a8..87578e70a 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs | |||
@@ -226,35 +226,16 @@ pub(super) fn element( | |||
226 | T![unsafe] => h | HlMod::Unsafe, | 226 | T![unsafe] => h | HlMod::Unsafe, |
227 | T![true] | T![false] => HlTag::BoolLiteral.into(), | 227 | T![true] | T![false] => HlTag::BoolLiteral.into(), |
228 | T![self] => { | 228 | T![self] => { |
229 | let self_param_is_mut = element | 229 | let self_param = element.parent().and_then(ast::SelfParam::cast); |
230 | .parent() | 230 | if let Some(NameClass::Definition(def)) = self_param |
231 | .and_then(ast::SelfParam::cast) | 231 | .and_then(|self_param| NameClass::classify_self_param(sema, &self_param)) |
232 | .and_then(|p| p.mut_token()) | ||
233 | .is_some(); | ||
234 | let self_path = &element | ||
235 | .parent() | ||
236 | .as_ref() | ||
237 | .and_then(SyntaxNode::parent) | ||
238 | .and_then(ast::Path::cast) | ||
239 | .and_then(|p| sema.resolve_path(&p)); | ||
240 | let mut h = HlTag::Symbol(SymbolKind::SelfParam).into(); | ||
241 | if self_param_is_mut | ||
242 | || matches!(self_path, | ||
243 | Some(hir::PathResolution::Local(local)) | ||
244 | if local.is_self(db) | ||
245 | && (local.is_mut(db) || local.ty(db).is_mutable_reference()) | ||
246 | ) | ||
247 | { | 232 | { |
248 | h |= HlMod::Mutable | 233 | highlight_def(db, def) | HlMod::Definition |
249 | } | 234 | } else if element.ancestors().any(|it| it.kind() == USE_TREE) { |
250 | 235 | HlTag::Symbol(SymbolKind::SelfParam).into() | |
251 | if let Some(hir::PathResolution::Local(local)) = self_path { | 236 | } else { |
252 | if is_consumed_lvalue(element, &local, db) { | 237 | return None; |
253 | h |= HlMod::Consuming; | ||
254 | } | ||
255 | } | 238 | } |
256 | |||
257 | h | ||
258 | } | 239 | } |
259 | T![ref] => element | 240 | T![ref] => element |
260 | .parent() | 241 | .parent() |
@@ -345,7 +326,9 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { | |||
345 | hir::GenericParam::LifetimeParam(_) => HlTag::Symbol(SymbolKind::LifetimeParam), | 326 | hir::GenericParam::LifetimeParam(_) => HlTag::Symbol(SymbolKind::LifetimeParam), |
346 | }, | 327 | }, |
347 | Definition::Local(local) => { | 328 | Definition::Local(local) => { |
348 | let tag = if local.is_param(db) { | 329 | let tag = if local.is_self(db) { |
330 | HlTag::Symbol(SymbolKind::SelfParam) | ||
331 | } else if local.is_param(db) { | ||
349 | HlTag::Symbol(SymbolKind::ValueParam) | 332 | HlTag::Symbol(SymbolKind::ValueParam) |
350 | } else { | 333 | } else { |
351 | HlTag::Symbol(SymbolKind::Local) | 334 | HlTag::Symbol(SymbolKind::Local) |