aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatol Liu <[email protected]>2020-11-05 04:08:46 +0000
committerAnatol Liu <[email protected]>2020-11-05 05:55:44 +0000
commit771c0d8c083e9c86a309a4380039602817e09fc8 (patch)
tree59d966962cee08a8194706e3d20d8d19ddee6265
parent3baa526fb07184ce9804a06c8e0251971eea3b49 (diff)
Add static semantic token modifier for associated functions with no &self
refactor logic into code_model.rs
-rw-r--r--crates/hir/src/code_model.rs23
-rw-r--r--crates/ide/src/syntax_highlighting.rs16
2 files changed, 22 insertions, 17 deletions
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;
41use stdx::impl_from; 41use stdx::impl_from;
42use syntax::{ 42use syntax::{
43 ast::{self, AttrsOwner, NameOwner}, 43 ast::{self, AttrsOwner, NameOwner},
44 AstNode, SmolStr, 44 AstNode, SmolStr, SyntaxKind,
45}; 45};
46use tt::{Ident, Leaf, Literal, TokenTree}; 46use tt::{Ident, Leaf, Literal, TokenTree};
47 47
@@ -788,8 +788,25 @@ impl Function {
788 db.function_data(self.id).has_body 788 db.function_data(self.id).has_body
789 } 789 }
790 790
791 pub fn source(self, db: &dyn HirDatabase) -> InFile<ast::Fn> { 791 /// whether this function is associated with some trait/impl
792 self.id.lookup(db.upcast()).source(db.upcast()) 792 pub fn is_associated(self, db: &dyn HirDatabase) -> bool {
793 if let Some(_) = self.self_param(db) {
794 return false;
795 }
796
797 let fn_parent_kind = self
798 .source(db)
799 .value
800 .syntax()
801 .parent()
802 .and_then(|s| s.parent())
803 .and_then(|s| Some(s.kind()));
804
805 match fn_parent_kind {
806 Some(SyntaxKind::IMPL) => true,
807 Some(SyntaxKind::TRAIT) => true,
808 _ => false,
809 }
793 } 810 }
794} 811}
795 812
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs
index c28ff849a..3fcdb5e52 100644
--- a/crates/ide/src/syntax_highlighting.rs
+++ b/crates/ide/src/syntax_highlighting.rs
@@ -746,20 +746,8 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
746 if func.is_unsafe(db) { 746 if func.is_unsafe(db) {
747 h |= HighlightModifier::Unsafe; 747 h |= HighlightModifier::Unsafe;
748 } 748 }
749 if let None = func.self_param(db) { 749 if func.is_associated(db) {
750 // if enclosing IMPL or TRAIT exists, this is a static method 750 h |= HighlightModifier::Static;
751 let fn_parent_kind = func
752 .source(db)
753 .value
754 .syntax()
755 .parent()
756 .and_then(|s| s.parent())
757 .and_then(|s| Some(s.kind()));
758 if let Some(SyntaxKind::IMPL) = fn_parent_kind {
759 h |= HighlightModifier::Static;
760 } else if let Some(SyntaxKind::TRAIT) = fn_parent_kind {
761 h |= HighlightModifier::Static;
762 }
763 } 751 }
764 return h; 752 return h;
765 } 753 }