aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/syntax_highlighting.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting.rs')
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs30
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};
20use rustc_hash::FxHashMap; 20use rustc_hash::FxHashMap;
21 21
22use crate::{call_info::call_info_for_token, references::classify_name_ref, Analysis, FileId}; 22use crate::{
23 call_info::call_info_for_token,
24 references::{classify_name_ref, NameRefClass},
25 Analysis, FileId,
26};
23 27
24pub(crate) use html::highlight_as_html; 28pub(crate) use html::highlight_as_html;
25pub use tags::{Highlight, HighlightModifier, HighlightModifiers, HighlightTag}; 29pub 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