diff options
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 1e5e0f420..8e793e479 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -1,7 +1,5 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use rustc_hash::FxHashMap; | ||
4 | |||
5 | use hir::{HirFileId, InFile, Name, SourceAnalyzer, SourceBinder}; | 3 | use hir::{HirFileId, InFile, Name, SourceAnalyzer, SourceBinder}; |
6 | use ra_db::SourceDatabase; | 4 | use ra_db::SourceDatabase; |
7 | use ra_ide_db::RootDatabase; | 5 | use ra_ide_db::RootDatabase; |
@@ -10,13 +8,11 @@ use ra_syntax::{ | |||
10 | ast, AstNode, Direction, SyntaxElement, SyntaxKind, SyntaxKind::*, SyntaxToken, TextRange, | 8 | ast, AstNode, Direction, SyntaxElement, SyntaxKind, SyntaxKind::*, SyntaxToken, TextRange, |
11 | WalkEvent, T, | 9 | WalkEvent, T, |
12 | }; | 10 | }; |
11 | use rustc_hash::FxHashMap; | ||
13 | 12 | ||
14 | use crate::{ | 13 | use crate::{ |
15 | expand::descend_into_macros_with_analyzer, | 14 | expand::descend_into_macros_with_analyzer, |
16 | references::{ | 15 | references::{classify_name, classify_name_ref, NameKind}, |
17 | classify_name, classify_name_ref, | ||
18 | NameKind::{self, *}, | ||
19 | }, | ||
20 | FileId, | 16 | FileId, |
21 | }; | 17 | }; |
22 | 18 | ||
@@ -193,7 +189,7 @@ fn highlight_node( | |||
193 | let name_kind = classify_name_ref(sb, node.with_value(&name_ref)).map(|d| d.kind); | 189 | let name_kind = classify_name_ref(sb, node.with_value(&name_ref)).map(|d| d.kind); |
194 | match name_kind { | 190 | match name_kind { |
195 | Some(name_kind) => { | 191 | Some(name_kind) => { |
196 | if let Local(local) = &name_kind { | 192 | if let NameKind::Local(local) = &name_kind { |
197 | if let Some(name) = local.name(db) { | 193 | if let Some(name) = local.name(db) { |
198 | let shadow_count = | 194 | let shadow_count = |
199 | bindings_shadow_count.entry(name.clone()).or_default(); | 195 | bindings_shadow_count.entry(name.clone()).or_default(); |
@@ -211,7 +207,7 @@ fn highlight_node( | |||
211 | let name = node.value.as_node().cloned().and_then(ast::Name::cast).unwrap(); | 207 | let name = node.value.as_node().cloned().and_then(ast::Name::cast).unwrap(); |
212 | let name_kind = classify_name(sb, node.with_value(&name)).map(|d| d.kind); | 208 | let name_kind = classify_name(sb, node.with_value(&name)).map(|d| d.kind); |
213 | 209 | ||
214 | if let Some(Local(local)) = &name_kind { | 210 | if let Some(NameKind::Local(local)) = &name_kind { |
215 | if let Some(name) = local.name(db) { | 211 | if let Some(name) = local.name(db) { |
216 | let shadow_count = bindings_shadow_count.entry(name.clone()).or_default(); | 212 | let shadow_count = bindings_shadow_count.entry(name.clone()).or_default(); |
217 | *shadow_count += 1; | 213 | *shadow_count += 1; |
@@ -316,20 +312,20 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo | |||
316 | 312 | ||
317 | fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str { | 313 | fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str { |
318 | match name_kind { | 314 | match name_kind { |
319 | Macro(_) => tags::MACRO, | 315 | NameKind::Macro(_) => tags::MACRO, |
320 | StructField(_) => tags::FIELD, | 316 | NameKind::StructField(_) => tags::FIELD, |
321 | ModuleDef(hir::ModuleDef::Module(_)) => tags::MODULE, | 317 | NameKind::ModuleDef(hir::ModuleDef::Module(_)) => tags::MODULE, |
322 | ModuleDef(hir::ModuleDef::Function(_)) => tags::FUNCTION, | 318 | NameKind::ModuleDef(hir::ModuleDef::Function(_)) => tags::FUNCTION, |
323 | ModuleDef(hir::ModuleDef::Adt(_)) => tags::TYPE, | 319 | NameKind::ModuleDef(hir::ModuleDef::Adt(_)) => tags::TYPE, |
324 | ModuleDef(hir::ModuleDef::EnumVariant(_)) => tags::CONSTANT, | 320 | NameKind::ModuleDef(hir::ModuleDef::EnumVariant(_)) => tags::CONSTANT, |
325 | ModuleDef(hir::ModuleDef::Const(_)) => tags::CONSTANT, | 321 | NameKind::ModuleDef(hir::ModuleDef::Const(_)) => tags::CONSTANT, |
326 | ModuleDef(hir::ModuleDef::Static(_)) => tags::CONSTANT, | 322 | NameKind::ModuleDef(hir::ModuleDef::Static(_)) => tags::CONSTANT, |
327 | ModuleDef(hir::ModuleDef::Trait(_)) => tags::TYPE, | 323 | NameKind::ModuleDef(hir::ModuleDef::Trait(_)) => tags::TYPE, |
328 | ModuleDef(hir::ModuleDef::TypeAlias(_)) => tags::TYPE, | 324 | NameKind::ModuleDef(hir::ModuleDef::TypeAlias(_)) => tags::TYPE, |
329 | ModuleDef(hir::ModuleDef::BuiltinType(_)) => tags::TYPE_BUILTIN, | 325 | NameKind::ModuleDef(hir::ModuleDef::BuiltinType(_)) => tags::TYPE_BUILTIN, |
330 | SelfType(_) => tags::TYPE_SELF, | 326 | NameKind::SelfType(_) => tags::TYPE_SELF, |
331 | TypeParam(_) => tags::TYPE_PARAM, | 327 | NameKind::TypeParam(_) => tags::TYPE_PARAM, |
332 | Local(local) => { | 328 | NameKind::Local(local) => { |
333 | if local.is_mut(db) || local.ty(db).is_mutable_reference() { | 329 | if local.is_mut(db) || local.ty(db).is_mutable_reference() { |
334 | tags::VARIABLE_MUT | 330 | tags::VARIABLE_MUT |
335 | } else { | 331 | } else { |