From 5da1dc9a8b6b568add92c30dca0341328c138b31 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Aug 2020 17:30:43 +0200 Subject: Better name --- crates/ide/src/syntax_highlighting.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 5521fd2b1..a87a9be7e 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -496,9 +496,9 @@ fn highlight_element( match name_kind { Some(NameClass::ExternCrate(_)) => HighlightTag::Module.into(), Some(NameClass::Definition(def)) => { - highlight_name(sema, db, def, None, false) | HighlightModifier::Definition + highlight_def(sema, db, def, None, false) | HighlightModifier::Definition } - Some(NameClass::ConstReference(def)) => highlight_name(sema, db, def, None, false), + Some(NameClass::ConstReference(def)) => highlight_def(sema, db, def, None, false), Some(NameClass::FieldShorthand { field, .. }) => { let mut h = HighlightTag::Field.into(); if let Definition::Field(field) = field { @@ -532,7 +532,7 @@ fn highlight_element( binding_hash = Some(calc_binding_hash(&name, *shadow_count)) } }; - highlight_name(sema, db, def, Some(name_ref), possibly_unsafe) + highlight_def(sema, db, def, Some(name_ref), possibly_unsafe) } NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(), }, @@ -737,7 +737,7 @@ fn highlight_method_call( Some(h) } -fn highlight_name( +fn highlight_def( sema: &Semantics, db: &RootDatabase, def: Definition, -- cgit v1.2.3 From 422ac441c29de730fe0adccc7bb3152ad5559039 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Aug 2020 17:31:26 +0200 Subject: Minor cleanups --- crates/ide/src/syntax_highlighting.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ide') diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index a87a9be7e..549c5efe7 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -520,7 +520,6 @@ fn highlight_element( NAME_REF => { let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap(); highlight_func_by_name_ref(sema, &name_ref).unwrap_or_else(|| { - let possibly_unsafe = is_possibly_unsafe(&name_ref); match classify_name_ref(sema, &name_ref) { Some(name_kind) => match name_kind { NameRefClass::ExternCrate(_) => HighlightTag::Module.into(), @@ -532,6 +531,7 @@ fn highlight_element( binding_hash = Some(calc_binding_hash(&name, *shadow_count)) } }; + let possibly_unsafe = is_possibly_unsafe(&name_ref); highlight_def(sema, db, def, Some(name_ref), possibly_unsafe) } NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(), -- cgit v1.2.3 From 0b62b990ba69efd23f26218d0461a2cef15e593a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Aug 2020 17:33:25 +0200 Subject: Minor --- crates/ide/src/syntax_highlighting.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 549c5efe7..38546ead3 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -706,8 +706,7 @@ fn highlight_func_by_name_ref( sema: &Semantics, name_ref: &ast::NameRef, ) -> Option { - let parent = name_ref.syntax().parent()?; - let method_call = ast::MethodCallExpr::cast(parent)?; + let method_call = name_ref.syntax().parent().and_then(ast::MethodCallExpr::cast)?; highlight_method_call(sema, &method_call) } -- cgit v1.2.3 From a9778c6d73c1ae609d9068a5aeb3e225d8154f59 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Aug 2020 17:37:19 +0200 Subject: Simplify --- crates/ide/src/syntax_highlighting.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 38546ead3..0a5f7a247 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -455,15 +455,10 @@ fn macro_call_range(macro_call: &ast::MacroCall) -> Option { } fn is_possibly_unsafe(name_ref: &ast::NameRef) -> bool { - name_ref - .syntax() - .parent() - .and_then(|parent| { - ast::FieldExpr::cast(parent.clone()) - .map(|_| true) - .or_else(|| ast::RecordPatField::cast(parent).map(|_| true)) - }) - .unwrap_or(false) + match name_ref.syntax().parent() { + Some(parent) => matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD), + None => false, + } } fn highlight_element( -- cgit v1.2.3 From 11a1bb1c3ec02456813ccb5cb0bdb76f9d39b2ec Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 19 Aug 2020 17:41:56 +0200 Subject: Inline trivial function --- crates/ide/src/syntax_highlighting.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 0a5f7a247..ad49f8e17 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -454,13 +454,6 @@ fn macro_call_range(macro_call: &ast::MacroCall) -> Option { Some(TextRange::new(range_start, range_end)) } -fn is_possibly_unsafe(name_ref: &ast::NameRef) -> bool { - match name_ref.syntax().parent() { - Some(parent) => matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD), - None => false, - } -} - fn highlight_element( sema: &Semantics, bindings_shadow_count: &mut FxHashMap, @@ -526,7 +519,12 @@ fn highlight_element( binding_hash = Some(calc_binding_hash(&name, *shadow_count)) } }; - let possibly_unsafe = is_possibly_unsafe(&name_ref); + let possibly_unsafe = match name_ref.syntax().parent() { + Some(parent) => { + matches!(parent.kind(), FIELD_EXPR | RECORD_PAT_FIELD) + } + None => false, + }; highlight_def(sema, db, def, Some(name_ref), possibly_unsafe) } NameRefClass::FieldShorthand { .. } => HighlightTag::Field.into(), -- cgit v1.2.3