diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-19 13:57:03 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-19 13:57:03 +0000 |
commit | 27587f3501168c0522e62bf14923aedbdc08a960 (patch) | |
tree | f323973f087ef0f47ef7015a930b09fefdf723a6 /crates/ra_ide/src/syntax_highlighting.rs | |
parent | ff415582960dbd91a18a092271c0848d6c90b0ec (diff) | |
parent | 372439dec88f8ce3350f29aa56801c8f30e59abe (diff) |
Merge #3236
3236: Merge NameDefinition and NameKind r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide/src/syntax_highlighting.rs')
-rw-r--r-- | crates/ra_ide/src/syntax_highlighting.rs | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 8e793e479..d873f153e 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use hir::{HirFileId, InFile, Name, SourceAnalyzer, SourceBinder}; | 3 | use hir::{HirFileId, InFile, Name, SourceAnalyzer, SourceBinder}; |
4 | use ra_db::SourceDatabase; | 4 | use ra_db::SourceDatabase; |
5 | use ra_ide_db::RootDatabase; | 5 | use ra_ide_db::{defs::NameDefinition, RootDatabase}; |
6 | use ra_prof::profile; | 6 | use ra_prof::profile; |
7 | use ra_syntax::{ | 7 | use ra_syntax::{ |
8 | ast, AstNode, Direction, SyntaxElement, SyntaxKind, SyntaxKind::*, SyntaxToken, TextRange, | 8 | ast, AstNode, Direction, SyntaxElement, SyntaxKind, SyntaxKind::*, SyntaxToken, TextRange, |
@@ -12,7 +12,7 @@ use rustc_hash::FxHashMap; | |||
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | expand::descend_into_macros_with_analyzer, | 14 | expand::descend_into_macros_with_analyzer, |
15 | references::{classify_name, classify_name_ref, NameKind}, | 15 | references::{classify_name, classify_name_ref}, |
16 | FileId, | 16 | FileId, |
17 | }; | 17 | }; |
18 | 18 | ||
@@ -186,10 +186,10 @@ fn highlight_node( | |||
186 | NAME_REF if node.value.ancestors().any(|it| it.kind() == ATTR) => return None, | 186 | NAME_REF if node.value.ancestors().any(|it| it.kind() == ATTR) => return None, |
187 | NAME_REF => { | 187 | NAME_REF => { |
188 | let name_ref = node.value.as_node().cloned().and_then(ast::NameRef::cast).unwrap(); | 188 | let name_ref = node.value.as_node().cloned().and_then(ast::NameRef::cast).unwrap(); |
189 | 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)); |
190 | match name_kind { | 190 | match name_kind { |
191 | Some(name_kind) => { | 191 | Some(name_kind) => { |
192 | if let NameKind::Local(local) = &name_kind { | 192 | if let NameDefinition::Local(local) = &name_kind { |
193 | if let Some(name) = local.name(db) { | 193 | if let Some(name) = local.name(db) { |
194 | let shadow_count = | 194 | let shadow_count = |
195 | bindings_shadow_count.entry(name.clone()).or_default(); | 195 | bindings_shadow_count.entry(name.clone()).or_default(); |
@@ -205,9 +205,9 @@ fn highlight_node( | |||
205 | } | 205 | } |
206 | NAME => { | 206 | NAME => { |
207 | 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(); |
208 | 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)); |
209 | 209 | ||
210 | if let Some(NameKind::Local(local)) = &name_kind { | 210 | if let Some(NameDefinition::Local(local)) = &name_kind { |
211 | if let Some(name) = local.name(db) { | 211 | if let Some(name) = local.name(db) { |
212 | let shadow_count = bindings_shadow_count.entry(name.clone()).or_default(); | 212 | let shadow_count = bindings_shadow_count.entry(name.clone()).or_default(); |
213 | *shadow_count += 1; | 213 | *shadow_count += 1; |
@@ -310,22 +310,22 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo | |||
310 | buf | 310 | buf |
311 | } | 311 | } |
312 | 312 | ||
313 | fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str { | 313 | fn highlight_name(db: &RootDatabase, def: NameDefinition) -> &'static str { |
314 | match name_kind { | 314 | match def { |
315 | NameKind::Macro(_) => tags::MACRO, | 315 | NameDefinition::Macro(_) => tags::MACRO, |
316 | NameKind::StructField(_) => tags::FIELD, | 316 | NameDefinition::StructField(_) => tags::FIELD, |
317 | NameKind::ModuleDef(hir::ModuleDef::Module(_)) => tags::MODULE, | 317 | NameDefinition::ModuleDef(hir::ModuleDef::Module(_)) => tags::MODULE, |
318 | NameKind::ModuleDef(hir::ModuleDef::Function(_)) => tags::FUNCTION, | 318 | NameDefinition::ModuleDef(hir::ModuleDef::Function(_)) => tags::FUNCTION, |
319 | NameKind::ModuleDef(hir::ModuleDef::Adt(_)) => tags::TYPE, | 319 | NameDefinition::ModuleDef(hir::ModuleDef::Adt(_)) => tags::TYPE, |
320 | NameKind::ModuleDef(hir::ModuleDef::EnumVariant(_)) => tags::CONSTANT, | 320 | NameDefinition::ModuleDef(hir::ModuleDef::EnumVariant(_)) => tags::CONSTANT, |
321 | NameKind::ModuleDef(hir::ModuleDef::Const(_)) => tags::CONSTANT, | 321 | NameDefinition::ModuleDef(hir::ModuleDef::Const(_)) => tags::CONSTANT, |
322 | NameKind::ModuleDef(hir::ModuleDef::Static(_)) => tags::CONSTANT, | 322 | NameDefinition::ModuleDef(hir::ModuleDef::Static(_)) => tags::CONSTANT, |
323 | NameKind::ModuleDef(hir::ModuleDef::Trait(_)) => tags::TYPE, | 323 | NameDefinition::ModuleDef(hir::ModuleDef::Trait(_)) => tags::TYPE, |
324 | NameKind::ModuleDef(hir::ModuleDef::TypeAlias(_)) => tags::TYPE, | 324 | NameDefinition::ModuleDef(hir::ModuleDef::TypeAlias(_)) => tags::TYPE, |
325 | NameKind::ModuleDef(hir::ModuleDef::BuiltinType(_)) => tags::TYPE_BUILTIN, | 325 | NameDefinition::ModuleDef(hir::ModuleDef::BuiltinType(_)) => tags::TYPE_BUILTIN, |
326 | NameKind::SelfType(_) => tags::TYPE_SELF, | 326 | NameDefinition::SelfType(_) => tags::TYPE_SELF, |
327 | NameKind::TypeParam(_) => tags::TYPE_PARAM, | 327 | NameDefinition::TypeParam(_) => tags::TYPE_PARAM, |
328 | NameKind::Local(local) => { | 328 | NameDefinition::Local(local) => { |
329 | if local.is_mut(db) || local.ty(db).is_mutable_reference() { | 329 | if local.is_mut(db) || local.ty(db).is_mutable_reference() { |
330 | tags::VARIABLE_MUT | 330 | tags::VARIABLE_MUT |
331 | } else { | 331 | } else { |