diff options
author | Aleksey Kladov <[email protected]> | 2020-03-02 18:00:38 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-03-02 18:00:38 +0000 |
commit | 2716a1fa3f8a7410248724a6ce5d4c28837db682 (patch) | |
tree | ad1faf323e4cb1478e1e34e2ed9fe858c5be80e5 /crates/ra_ide/src/syntax_highlighting.rs | |
parent | 96eca8a1abd79840b9040250db9d1e65ec663b0e (diff) |
More principled approach for gotodef for field shorhand
Callers can now decide for themselves if they should prefer field or
local definition. By default, it's the local.
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting.rs')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 28117b4d8..b89501aff 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -19,7 +19,11 @@ use ra_syntax::{ | |||
19 | }; | 19 | }; |
20 | use rustc_hash::FxHashMap; | 20 | use rustc_hash::FxHashMap; |
21 | 21 | ||
22 | use crate::{call_info::call_info_for_token, references::classify_name_ref, Analysis, FileId}; | 22 | use crate::{ |
23 | call_info::call_info_for_token, | ||
24 | references::{classify_name_ref, NameRefClass}, | ||
25 | Analysis, FileId, | ||
26 | }; | ||
23 | 27 | ||
24 | pub(crate) use html::highlight_as_html; | 28 | pub(crate) use html::highlight_as_html; |
25 | pub use tags::{Highlight, HighlightModifier, HighlightModifiers, HighlightTag}; | 29 | pub use tags::{Highlight, HighlightModifier, HighlightModifiers, HighlightTag}; |
@@ -186,24 +190,24 @@ fn highlight_element( | |||
186 | } | 190 | } |
187 | 191 | ||
188 | // Highlight references like the definitions they resolve to | 192 | // Highlight references like the definitions they resolve to |
189 | |||
190 | // Special-case field init shorthand | ||
191 | NAME_REF if element.parent().and_then(ast::RecordField::cast).is_some() => { | ||
192 | HighlightTag::Field.into() | ||
193 | } | ||
194 | NAME_REF if element.ancestors().any(|it| it.kind() == ATTR) => return None, | 193 | NAME_REF if element.ancestors().any(|it| it.kind() == ATTR) => return None, |
195 | NAME_REF => { | 194 | NAME_REF => { |
196 | let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap(); | 195 | let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap(); |
197 | let name_kind = classify_name_ref(sema, &name_ref)?; | 196 | let name_kind = classify_name_ref(sema, &name_ref)?; |
198 | 197 | ||
199 | if let NameDefinition::Local(local) = &name_kind { | 198 | match name_kind { |
200 | if let Some(name) = local.name(db) { | 199 | NameRefClass::NameDefinition(def) => { |
201 | let shadow_count = bindings_shadow_count.entry(name.clone()).or_default(); | 200 | if let NameDefinition::Local(local) = &def { |
202 | binding_hash = Some(calc_binding_hash(&name, *shadow_count)) | 201 | if let Some(name) = local.name(db) { |
202 | let shadow_count = | ||
203 | bindings_shadow_count.entry(name.clone()).or_default(); | ||
204 | binding_hash = Some(calc_binding_hash(&name, *shadow_count)) | ||
205 | } | ||
206 | }; | ||
207 | highlight_name(db, def) | ||
203 | } | 208 | } |
204 | }; | 209 | NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(), |
205 | 210 | } | |
206 | highlight_name(db, name_kind) | ||
207 | } | 211 | } |
208 | 212 | ||
209 | // Simple token-based highlighting | 213 | // Simple token-based highlighting |