mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Merge #6472
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:
commit
0a715cfbd2
7 changed files with 95 additions and 3 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue