6472: Add `static` modifier for associated functions r=matklad a=p3achyjr

Adds static semantic token modifier to associated functions, resolves #6194 

## Info

- Associated functions are more-or-less equivalent to static methods in other languages. This PR checks, for each function, whether that function has a self_param, and whether it's enclosed in a trait/impl.

## Changes

- Added method ```is_associated``` to code_model::Function. This basically gets the source from the ast, and checks whether the enclosing scope is an impl or trait.
- Added `static` to HighlightModifiers
- Added unit test

## Tests

- Ran ```cargo test```

Co-authored-by: Anatol Liu <axlui@anatols-mbp.lan>
This commit is contained in:
bors[bot] 2020-11-09 21:13:51 +00:00 committed by GitHub
commit 0a715cfbd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 95 additions and 3 deletions

View file

@ -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,6 +746,9 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
if func.is_unsafe(db) {
h |= HighlightModifier::Unsafe;
}
if func.as_assoc_item(db).is_some() && func.self_param(db).is_none() {
h |= HighlightModifier::Static;
}
return h;
}
hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct,