From 209eb32796c6fd56d1b378690c807cf73ce54235 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 28 Feb 2020 15:27:52 +0100 Subject: Classify name takes const patterns into account --- crates/ra_ide/src/syntax_highlighting.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'crates/ra_ide/src/syntax_highlighting.rs') diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index c0f7c1c9f..6312bcb83 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -7,7 +7,7 @@ mod tests; use hir::{Name, Semantics}; use ra_ide_db::{ - defs::{classify_name, NameDefinition}, + defs::{classify_name, NameClass, NameDefinition}, RootDatabase, }; use ra_prof::profile; @@ -169,7 +169,7 @@ fn highlight_element( let name = element.into_node().and_then(ast::Name::cast).unwrap(); let name_kind = classify_name(sema, &name); - if let Some(NameDefinition::Local(local)) = &name_kind { + if let Some(NameClass::NameDefinition(NameDefinition::Local(local))) = &name_kind { if let Some(name) = local.name(db) { let shadow_count = bindings_shadow_count.entry(name.clone()).or_default(); *shadow_count += 1; @@ -177,11 +177,13 @@ fn highlight_element( } }; - let h = match name_kind { - Some(name_kind) => highlight_name(db, name_kind), - None => highlight_name_by_syntax(name), - }; - h | HighlightModifier::Definition + match name_kind { + Some(NameClass::NameDefinition(def)) => { + highlight_name(db, def) | HighlightModifier::Definition + } + Some(NameClass::ConstReference(def)) => highlight_name(db, def), + None => highlight_name_by_syntax(name) | HighlightModifier::Definition, + } } // Highlight references like the definitions they resolve to -- cgit v1.2.3 From 56ce34c6a7ec0b4426d4cb25e10512c7efaf6f06 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 28 Feb 2020 16:49:46 +0100 Subject: Correctly flag 'lifetime definitions as definitions --- crates/ra_ide/src/syntax_highlighting.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide/src/syntax_highlighting.rs') diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 6312bcb83..b94b6a022 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -214,8 +214,13 @@ fn highlight_element( INT_NUMBER | FLOAT_NUMBER => HighlightTag::NumericLiteral.into(), BYTE => HighlightTag::ByteLiteral.into(), CHAR => HighlightTag::CharLiteral.into(), - // FIXME: set Declaration for decls - LIFETIME => HighlightTag::Lifetime.into(), + LIFETIME => { + let h = Highlight::new(HighlightTag::Lifetime); + dbg!(match element.parent().map(|it| it.kind()) { + Some(LIFETIME_PARAM) | Some(LABEL) => h | HighlightModifier::Definition, + _ => h, + }) + } k if k.is_keyword() => { let h = Highlight::new(HighlightTag::Keyword); -- cgit v1.2.3