diff options
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r-- | crates/ra_ide_api/src/snapshots/highlighting.html | 8 | ||||
-rw-r--r-- | crates/ra_ide_api/src/syntax_highlighting.rs | 89 |
2 files changed, 55 insertions, 42 deletions
diff --git a/crates/ra_ide_api/src/snapshots/highlighting.html b/crates/ra_ide_api/src/snapshots/highlighting.html index 2a32b3241..d79d35bf3 100644 --- a/crates/ra_ide_api/src/snapshots/highlighting.html +++ b/crates/ra_ide_api/src/snapshots/highlighting.html | |||
@@ -19,13 +19,13 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4e | |||
19 | </style> | 19 | </style> |
20 | <pre><code><span class="attribute">#</span><span class="attribute">[</span><span class="attribute">derive</span><span class="attribute">(</span><span class="attribute">Clone</span><span class="attribute">,</span><span class="attribute"> </span><span class="attribute">Debug</span><span class="attribute">)</span><span class="attribute">]</span> | 20 | <pre><code><span class="attribute">#</span><span class="attribute">[</span><span class="attribute">derive</span><span class="attribute">(</span><span class="attribute">Clone</span><span class="attribute">,</span><span class="attribute"> </span><span class="attribute">Debug</span><span class="attribute">)</span><span class="attribute">]</span> |
21 | <span class="keyword">struct</span> <span class="type">Foo</span> { | 21 | <span class="keyword">struct</span> <span class="type">Foo</span> { |
22 | <span class="keyword">pub</span> <span class="function">x</span>: <span class="text">i32</span>, | 22 | <span class="keyword">pub</span> <span class="function">x</span>: <span class="type">i32</span>, |
23 | <span class="keyword">pub</span> <span class="function">y</span>: <span class="text">i32</span>, | 23 | <span class="keyword">pub</span> <span class="function">y</span>: <span class="type">i32</span>, |
24 | } | 24 | } |
25 | 25 | ||
26 | <span class="keyword">fn</span> <span class="function">foo</span><<span class="type type">T</span>>() -> <span class="type">T</span> { | 26 | <span class="keyword">fn</span> <span class="function">foo</span><<span class="type">T</span>>() -> <span class="type">T</span> { |
27 | <span class="macro">unimplemented</span><span class="macro">!</span>(); | 27 | <span class="macro">unimplemented</span><span class="macro">!</span>(); |
28 | <span class="function">foo</span>::<<span class="type text">i32</span>>(); | 28 | <span class="function">foo</span>::<<span class="type">i32</span>>(); |
29 | } | 29 | } |
30 | 30 | ||
31 | <span class="comment">// comment</span> | 31 | <span class="comment">// comment</span> |
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index bf4e9c9d1..4b24754a8 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs | |||
@@ -30,6 +30,14 @@ fn is_control_keyword(kind: SyntaxKind) -> bool { | |||
30 | } | 30 | } |
31 | } | 31 | } |
32 | 32 | ||
33 | fn 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 | |||
33 | pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> { | 41 | pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> { |
34 | let _p = profile("highlight"); | 42 | let _p = profile("highlight"); |
35 | let source_file = db.parse(file_id).tree; | 43 | let source_file = db.parse(file_id).tree; |
@@ -62,46 +70,52 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa | |||
62 | ATTR => "attribute", | 70 | ATTR => "attribute", |
63 | NAME_REF => { | 71 | NAME_REF => { |
64 | if let Some(name_ref) = node.as_node().and_then(ast::NameRef::cast) { | 72 | if let Some(name_ref) = node.as_node().and_then(ast::NameRef::cast) { |
65 | use crate::name_ref_kind::{classify_name_ref, NameRefKind::*}; | 73 | // FIXME: revisit this after #1340 |
66 | use hir::{ModuleDef, ImplItem}; | 74 | if is_prim_type(name_ref) { |
75 | "type" | ||
76 | } else { | ||
77 | use crate::name_ref_kind::{classify_name_ref, NameRefKind::*}; | ||
78 | use hir::{ModuleDef, ImplItem}; | ||
67 | 79 | ||
68 | // FIXME: try to reuse the SourceAnalyzers | 80 | // FIXME: try to reuse the SourceAnalyzers |
69 | let analyzer = hir::SourceAnalyzer::new(db, file_id, name_ref.syntax(), None); | 81 | let analyzer = |
70 | match classify_name_ref(db, &analyzer, name_ref) { | 82 | hir::SourceAnalyzer::new(db, file_id, name_ref.syntax(), None); |
71 | Some(Method(_)) => "function", | 83 | match classify_name_ref(db, &analyzer, name_ref) { |
72 | Some(Macro(_)) => "macro", | 84 | Some(Method(_)) => "function", |
73 | Some(FieldAccess(_)) => "field", | 85 | Some(Macro(_)) => "macro", |
74 | Some(AssocItem(ImplItem::Method(_))) => "function", | 86 | Some(FieldAccess(_)) => "field", |
75 | Some(AssocItem(ImplItem::Const(_))) => "constant", | 87 | Some(AssocItem(ImplItem::Method(_))) => "function", |
76 | Some(AssocItem(ImplItem::TypeAlias(_))) => "type", | 88 | Some(AssocItem(ImplItem::Const(_))) => "constant", |
77 | Some(Def(ModuleDef::Module(_))) => "module", | 89 | Some(AssocItem(ImplItem::TypeAlias(_))) => "type", |
78 | Some(Def(ModuleDef::Function(_))) => "function", | 90 | Some(Def(ModuleDef::Module(_))) => "module", |
79 | Some(Def(ModuleDef::Struct(_))) => "type", | 91 | Some(Def(ModuleDef::Function(_))) => "function", |
80 | Some(Def(ModuleDef::Union(_))) => "type", | 92 | Some(Def(ModuleDef::Struct(_))) => "type", |
81 | Some(Def(ModuleDef::Enum(_))) => "type", | 93 | Some(Def(ModuleDef::Union(_))) => "type", |
82 | Some(Def(ModuleDef::EnumVariant(_))) => "constant", | 94 | Some(Def(ModuleDef::Enum(_))) => "type", |
83 | Some(Def(ModuleDef::Const(_))) => "constant", | 95 | Some(Def(ModuleDef::EnumVariant(_))) => "constant", |
84 | Some(Def(ModuleDef::Static(_))) => "constant", | 96 | Some(Def(ModuleDef::Const(_))) => "constant", |
85 | Some(Def(ModuleDef::Trait(_))) => "type", | 97 | Some(Def(ModuleDef::Static(_))) => "constant", |
86 | Some(Def(ModuleDef::TypeAlias(_))) => "type", | 98 | Some(Def(ModuleDef::Trait(_))) => "type", |
87 | Some(SelfType(_)) => "type", | 99 | Some(Def(ModuleDef::TypeAlias(_))) => "type", |
88 | Some(Pat(ptr)) => { | 100 | Some(SelfType(_)) => "type", |
89 | binding_hash = Some({ | 101 | Some(Pat(ptr)) => { |
90 | let text = ptr | 102 | binding_hash = Some({ |
91 | .syntax_node_ptr() | 103 | let text = ptr |
92 | .to_node(&source_file.syntax()) | 104 | .syntax_node_ptr() |
93 | .text() | 105 | .to_node(&source_file.syntax()) |
94 | .to_smol_string(); | 106 | .text() |
95 | let shadow_count = | 107 | .to_smol_string(); |
96 | bindings_shadow_count.entry(text.clone()).or_default(); | 108 | let shadow_count = |
97 | calc_binding_hash(file_id, &text, *shadow_count) | 109 | bindings_shadow_count.entry(text.clone()).or_default(); |
98 | }); | 110 | calc_binding_hash(file_id, &text, *shadow_count) |
111 | }); | ||
99 | 112 | ||
100 | "variable" | 113 | "variable" |
114 | } | ||
115 | Some(SelfParam(_)) => "type", | ||
116 | Some(GenericParam(_)) => "type", | ||
117 | None => "text", | ||
101 | } | 118 | } |
102 | Some(SelfParam(_)) => "type", | ||
103 | Some(GenericParam(_)) => "type", | ||
104 | None => "text", | ||
105 | } | 119 | } |
106 | } else { | 120 | } else { |
107 | "text" | 121 | "text" |
@@ -138,7 +152,6 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa | |||
138 | "text" | 152 | "text" |
139 | } | 153 | } |
140 | } | 154 | } |
141 | TYPE_ALIAS_DEF | TYPE_ARG | TYPE_PARAM => "type", | ||
142 | INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal", | 155 | INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal", |
143 | LIFETIME => "parameter", | 156 | LIFETIME => "parameter", |
144 | T![unsafe] => "keyword.unsafe", | 157 | T![unsafe] => "keyword.unsafe", |