Add static semantic token modifier for associated functions with no &self
refactor logic into code_model.rs
This commit is contained in:
parent
3baa526fb0
commit
771c0d8c08
@ -41,7 +41,7 @@
|
||||
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 @@ pub fn has_body(self, db: &dyn HirDatabase) -> bool {
|
||||
db.function_data(self.id).has_body
|
||||
}
|
||||
|
||||
pub fn source(self, db: &dyn HirDatabase) -> InFile<ast::Fn> {
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -746,20 +746,8 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
|
||||
if func.is_unsafe(db) {
|
||||
h |= HighlightModifier::Unsafe;
|
||||
}
|
||||
if let None = func.self_param(db) {
|
||||
// if enclosing IMPL or TRAIT exists, this is a static method
|
||||
let fn_parent_kind = func
|
||||
.source(db)
|
||||
.value
|
||||
.syntax()
|
||||
.parent()
|
||||
.and_then(|s| s.parent())
|
||||
.and_then(|s| Some(s.kind()));
|
||||
if let Some(SyntaxKind::IMPL) = fn_parent_kind {
|
||||
if func.is_associated(db) {
|
||||
h |= HighlightModifier::Static;
|
||||
} else if let Some(SyntaxKind::TRAIT) = fn_parent_kind {
|
||||
h |= HighlightModifier::Static;
|
||||
}
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user