From 771c0d8c083e9c86a309a4380039602817e09fc8 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 --- crates/hir/src/code_model.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'crates/hir/src') diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index afb849b4d..d04de053f 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, + AstNode, SmolStr, SyntaxKind, }; use tt::{Ident, Leaf, Literal, TokenTree}; @@ -788,8 +788,25 @@ impl Function { db.function_data(self.id).has_body } - pub fn source(self, db: &dyn HirDatabase) -> InFile { - self.id.lookup(db.upcast()).source(db.upcast()) + /// whether this function is associated with some trait/impl + pub fn is_associated(self, db: &dyn HirDatabase) -> bool { + if let Some(_) = self.self_param(db) { + return false; + } + + let fn_parent_kind = self + .source(db) + .value + .syntax() + .parent() + .and_then(|s| s.parent()) + .and_then(|s| Some(s.kind())); + + match fn_parent_kind { + Some(SyntaxKind::IMPL) => true, + Some(SyntaxKind::TRAIT) => true, + _ => false, + } } } -- cgit v1.2.3