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.rs88
1 files changed, 38 insertions, 50 deletions
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs
index 4b24754a8..3a04a51cd 100644
--- a/crates/ra_ide_api/src/syntax_highlighting.rs
+++ b/crates/ra_ide_api/src/syntax_highlighting.rs
@@ -30,14 +30,6 @@ fn is_control_keyword(kind: SyntaxKind) -> bool {
30 } 30 }
31} 31}
32 32
33fn is_prim_type(node: &ast::NameRef) -> bool {
34 match node.text().as_str() {
35 "u8" | "i8" | "u16" | "i16" | "u32" | "i32" | "u64" | "i64" | "u128" | "i128" | "usize"
36 | "isize" | "f32" | "f64" | "bool" | "char" | "str" => true,
37 _ => false,
38 }
39}
40
41pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> { 33pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> {
42 let _p = profile("highlight"); 34 let _p = profile("highlight");
43 let source_file = db.parse(file_id).tree; 35 let source_file = db.parse(file_id).tree;
@@ -71,51 +63,47 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
71 NAME_REF => { 63 NAME_REF => {
72 if let Some(name_ref) = node.as_node().and_then(ast::NameRef::cast) { 64 if let Some(name_ref) = node.as_node().and_then(ast::NameRef::cast) {
73 // FIXME: revisit this after #1340 65 // FIXME: revisit this after #1340
74 if is_prim_type(name_ref) { 66 use crate::name_ref_kind::{classify_name_ref, NameRefKind::*};
75 "type" 67 use hir::{ModuleDef, ImplItem};
76 } else {
77 use crate::name_ref_kind::{classify_name_ref, NameRefKind::*};
78 use hir::{ModuleDef, ImplItem};
79 68
80 // FIXME: try to reuse the SourceAnalyzers 69 // FIXME: try to reuse the SourceAnalyzers
81 let analyzer = 70 let analyzer = hir::SourceAnalyzer::new(db, file_id, name_ref.syntax(), None);
82 hir::SourceAnalyzer::new(db, file_id, name_ref.syntax(), None); 71 match classify_name_ref(db, &analyzer, name_ref) {
83 match classify_name_ref(db, &analyzer, name_ref) { 72 Some(Method(_)) => "function",
84 Some(Method(_)) => "function", 73 Some(Macro(_)) => "macro",
85 Some(Macro(_)) => "macro", 74 Some(FieldAccess(_)) => "field",
86 Some(FieldAccess(_)) => "field", 75 Some(AssocItem(ImplItem::Method(_))) => "function",
87 Some(AssocItem(ImplItem::Method(_))) => "function", 76 Some(AssocItem(ImplItem::Const(_))) => "constant",
88 Some(AssocItem(ImplItem::Const(_))) => "constant", 77 Some(AssocItem(ImplItem::TypeAlias(_))) => "type",
89 Some(AssocItem(ImplItem::TypeAlias(_))) => "type", 78 Some(Def(ModuleDef::Module(_))) => "module",
90 Some(Def(ModuleDef::Module(_))) => "module", 79 Some(Def(ModuleDef::Function(_))) => "function",
91 Some(Def(ModuleDef::Function(_))) => "function", 80 Some(Def(ModuleDef::Struct(_))) => "type",
92 Some(Def(ModuleDef::Struct(_))) => "type", 81 Some(Def(ModuleDef::Union(_))) => "type",
93 Some(Def(ModuleDef::Union(_))) => "type", 82 Some(Def(ModuleDef::Enum(_))) => "type",
94 Some(Def(ModuleDef::Enum(_))) => "type", 83 Some(Def(ModuleDef::EnumVariant(_))) => "constant",
95 Some(Def(ModuleDef::EnumVariant(_))) => "constant", 84 Some(Def(ModuleDef::Const(_))) => "constant",
96 Some(Def(ModuleDef::Const(_))) => "constant", 85 Some(Def(ModuleDef::Static(_))) => "constant",
97 Some(Def(ModuleDef::Static(_))) => "constant", 86 Some(Def(ModuleDef::Trait(_))) => "type",
98 Some(Def(ModuleDef::Trait(_))) => "type", 87 Some(Def(ModuleDef::TypeAlias(_))) => "type",
99 Some(Def(ModuleDef::TypeAlias(_))) => "type", 88 Some(Def(ModuleDef::BuiltinType(_))) => "type",
100 Some(SelfType(_)) => "type", 89 Some(SelfType(_)) => "type",
101 Some(Pat(ptr)) => { 90 Some(Pat(ptr)) => {
102 binding_hash = Some({ 91 binding_hash = Some({
103 let text = ptr 92 let text = ptr
104 .syntax_node_ptr() 93 .syntax_node_ptr()
105 .to_node(&source_file.syntax()) 94 .to_node(&source_file.syntax())
106 .text() 95 .text()
107 .to_smol_string(); 96 .to_smol_string();
108 let shadow_count = 97 let shadow_count =
109 bindings_shadow_count.entry(text.clone()).or_default(); 98 bindings_shadow_count.entry(text.clone()).or_default();
110 calc_binding_hash(file_id, &text, *shadow_count) 99 calc_binding_hash(file_id, &text, *shadow_count)
111 }); 100 });
112 101
113 "variable" 102 "variable"
114 }
115 Some(SelfParam(_)) => "type",
116 Some(GenericParam(_)) => "type",
117 None => "text",
118 } 103 }
104 Some(SelfParam(_)) => "type",
105 Some(GenericParam(_)) => "type",
106 None => "text",
119 } 107 }
120 } else { 108 } else {
121 "text" 109 "text"