mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 23:24:29 +00:00
8024: Added the trait modifier for methods
method in impls and method calls will have trait modifier.
This commit is contained in:
parent
fd7c454d51
commit
f269fe7156
4 changed files with 24 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
//! Computes color for a single element.
|
||||
|
||||
use hir::{AsAssocItem, Semantics, VariantDef};
|
||||
use hir::{AsAssocItem, AssocItemContainer, Semantics, VariantDef};
|
||||
use ide_db::{
|
||||
defs::{Definition, NameClass, NameRefClass},
|
||||
RootDatabase, SymbolKind,
|
||||
|
@ -275,6 +275,19 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
|
|||
hir::ModuleDef::Module(_) => HlTag::Symbol(SymbolKind::Module),
|
||||
hir::ModuleDef::Function(func) => {
|
||||
let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Function));
|
||||
if let Some(item) = func.as_assoc_item(db) {
|
||||
match item.container(db) {
|
||||
AssocItemContainer::Impl(i) => {
|
||||
if i.target_trait(db).is_some() {
|
||||
h |= HlMod::Trait;
|
||||
}
|
||||
}
|
||||
AssocItemContainer::Trait(_t) => {
|
||||
h |= HlMod::Trait;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if func.as_assoc_item(db).is_some() {
|
||||
h |= HlMod::Associated;
|
||||
if func.self_param(db).is_none() {
|
||||
|
@ -362,6 +375,10 @@ fn highlight_method_call(
|
|||
if func.is_unsafe(sema.db) || sema.is_unsafe_method_call(&method_call) {
|
||||
h |= HlMod::Unsafe;
|
||||
}
|
||||
if let Some(_t) = func.as_assoc_item(sema.db)?.containing_trait(sema.db) {
|
||||
h |= HlMod::Trait
|
||||
}
|
||||
|
||||
if let Some(self_param) = func.self_param(sema.db) {
|
||||
match self_param.access(sema.db) {
|
||||
hir::Access::Shared => (),
|
||||
|
|
|
@ -58,6 +58,8 @@ pub enum HlMod {
|
|||
Associated,
|
||||
/// Used for intra doc links in doc injection.
|
||||
IntraDocLink,
|
||||
/// Used for trait items in impls.
|
||||
Trait,
|
||||
|
||||
/// Keep this last!
|
||||
Unsafe,
|
||||
|
@ -158,6 +160,7 @@ impl HlMod {
|
|||
HlMod::Callable,
|
||||
HlMod::Static,
|
||||
HlMod::Associated,
|
||||
HlMod::Trait,
|
||||
HlMod::Unsafe,
|
||||
];
|
||||
|
||||
|
@ -174,6 +177,7 @@ impl HlMod {
|
|||
HlMod::IntraDocLink => "intra_doc_link",
|
||||
HlMod::Mutable => "mutable",
|
||||
HlMod::Static => "static",
|
||||
HlMod::Trait => "trait",
|
||||
HlMod::Unsafe => "unsafe",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,6 +88,7 @@ define_semantic_token_modifiers![
|
|||
(CONSUMING, "consuming"),
|
||||
(UNSAFE, "unsafe"),
|
||||
(ATTRIBUTE_MODIFIER, "attribute"),
|
||||
(TRAIT_MODIFIER, "trait"),
|
||||
(CALLABLE, "callable"),
|
||||
(INTRA_DOC_LINK, "intraDocLink"),
|
||||
];
|
||||
|
|
|
@ -474,6 +474,7 @@ fn semantic_token_type_and_modifiers(
|
|||
HlMod::Callable => semantic_tokens::CALLABLE,
|
||||
HlMod::Static => lsp_types::SemanticTokenModifier::STATIC,
|
||||
HlMod::IntraDocLink => semantic_tokens::INTRA_DOC_LINK,
|
||||
HlMod::Trait => semantic_tokens::TRAIT_MODIFIER,
|
||||
HlMod::Associated => continue,
|
||||
};
|
||||
mods |= modifier;
|
||||
|
|
Loading…
Reference in a new issue