aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/syntax_highlighting.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/syntax_highlighting.rs')
-rw-r--r--crates/ra_ide_api/src/syntax_highlighting.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs
index 9ae2dc061..33f3caceb 100644
--- a/crates/ra_ide_api/src/syntax_highlighting.rs
+++ b/crates/ra_ide_api/src/syntax_highlighting.rs
@@ -14,7 +14,7 @@ use ra_syntax::{
14 14
15use crate::{ 15use crate::{
16 db::RootDatabase, 16 db::RootDatabase,
17 name_ref_kind::{classify_name_ref, NameRefKind::*}, 17 references::{classify_name_ref, NameKind::*},
18 FileId, 18 FileId,
19}; 19};
20 20
@@ -97,13 +97,14 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
97 STRING | RAW_STRING | RAW_BYTE_STRING | BYTE_STRING => "string", 97 STRING | RAW_STRING | RAW_BYTE_STRING | BYTE_STRING => "string",
98 ATTR => "attribute", 98 ATTR => "attribute",
99 NAME_REF => { 99 NAME_REF => {
100 if node.ancestors().any(|it| it.kind() == ATTR) {
101 continue;
102 }
100 if let Some(name_ref) = node.as_node().cloned().and_then(ast::NameRef::cast) { 103 if let Some(name_ref) = node.as_node().cloned().and_then(ast::NameRef::cast) {
101 // FIXME: try to reuse the SourceAnalyzers 104 let name_kind = classify_name_ref(db, file_id, &name_ref).map(|d| d.kind);
102 let analyzer = hir::SourceAnalyzer::new(db, file_id, name_ref.syntax(), None); 105 match name_kind {
103 match classify_name_ref(db, &analyzer, &name_ref) {
104 Some(Method(_)) => "function",
105 Some(Macro(_)) => "macro", 106 Some(Macro(_)) => "macro",
106 Some(FieldAccess(_)) => "field", 107 Some(Field(_)) => "field",
107 Some(AssocItem(hir::AssocItem::Function(_))) => "function", 108 Some(AssocItem(hir::AssocItem::Function(_))) => "function",
108 Some(AssocItem(hir::AssocItem::Const(_))) => "constant", 109 Some(AssocItem(hir::AssocItem::Const(_))) => "constant",
109 Some(AssocItem(hir::AssocItem::TypeAlias(_))) => "type", 110 Some(AssocItem(hir::AssocItem::TypeAlias(_))) => "type",
@@ -117,7 +118,7 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
117 Some(Def(hir::ModuleDef::TypeAlias(_))) => "type", 118 Some(Def(hir::ModuleDef::TypeAlias(_))) => "type",
118 Some(Def(hir::ModuleDef::BuiltinType(_))) => "type", 119 Some(Def(hir::ModuleDef::BuiltinType(_))) => "type",
119 Some(SelfType(_)) => "type", 120 Some(SelfType(_)) => "type",
120 Some(Pat(ptr)) => { 121 Some(Pat((_, ptr))) => {
121 let pat = ptr.to_node(&root); 122 let pat = ptr.to_node(&root);
122 if let Some(name) = pat.name() { 123 if let Some(name) = pat.name() {
123 let text = name.text(); 124 let text = name.text();
@@ -127,6 +128,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
127 Some(calc_binding_hash(file_id, &text, *shadow_count)) 128 Some(calc_binding_hash(file_id, &text, *shadow_count))
128 } 129 }
129 130
131 let analyzer =
132 hir::SourceAnalyzer::new(db, file_id, name_ref.syntax(), None);
130 if is_variable_mutable(db, &analyzer, ptr.to_node(&root)) { 133 if is_variable_mutable(db, &analyzer, ptr.to_node(&root)) {
131 "variable.mut" 134 "variable.mut"
132 } else { 135 } else {