From 6b950d24d44c6de4de3486832676359b2dfcb7c8 Mon Sep 17 00:00:00 2001 From: Anatol Liu Date: Wed, 4 Nov 2020 20:08:46 -0800 Subject: Add static semantic token modifier for associated functions with no &self refactor logic into code_model.rs address comments --- crates/hir/src/code_model.rs | 15 +-------------- crates/ide/src/syntax_highlighting.rs | 4 ++-- 2 files changed, 3 insertions(+), 16 deletions(-) (limited to 'crates') diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index fadd010e2..30a5e4580 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -41,7 +41,7 @@ use rustc_hash::FxHashSet; use stdx::impl_from; use syntax::{ ast::{self, AttrsOwner, NameOwner}, - AstNode, SmolStr, SyntaxKind, + AstNode, SmolStr, }; use tt::{Ident, Leaf, Literal, TokenTree}; @@ -787,19 +787,6 @@ impl Function { pub fn has_body(self, db: &dyn HirDatabase) -> bool { db.function_data(self.id).has_body } - - /// whether this function is associated with some trait/impl - pub fn is_assoc_item(self, db: &dyn HirDatabase) -> bool { - let fn_parent_kind = self - .source(db) - .value - .syntax() - .parent() - .and_then(|s| s.parent()) - .and_then(|s| Some(s.kind())); - - matches!(fn_parent_kind, Some(SyntaxKind::IMPL) | Some(SyntaxKind::TRAIT)) - } } // Note: logically, this belongs to `hir_ty`, but we are not using it there yet. diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 41fd36edf..4a01097df 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -6,7 +6,7 @@ pub(crate) mod tags; #[cfg(test)] mod tests; -use hir::{Local, Name, Semantics, VariantDef}; +use hir::{AsAssocItem, Local, Name, Semantics, VariantDef}; use ide_db::{ defs::{Definition, NameClass, NameRefClass}, RootDatabase, @@ -746,7 +746,7 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { if func.is_unsafe(db) { h |= HighlightModifier::Unsafe; } - if func.is_assoc_item(db) && func.self_param(db).is_none() { + if func.as_assoc_item(db).is_some() && func.self_param(db).is_none() { h |= HighlightModifier::Static; } return h; -- cgit v1.2.3