From f269fe71569984dea7738926d164f284552196ed Mon Sep 17 00:00:00 2001 From: Chetan Khilosiya Date: Mon, 29 Mar 2021 22:57:05 +0530 Subject: 8024: Added the trait modifier for methods method in impls and method calls will have trait modifier. --- crates/ide/src/syntax_highlighting/highlight.rs | 19 ++++++++++++++++++- crates/ide/src/syntax_highlighting/tags.rs | 4 ++++ crates/rust-analyzer/src/semantic_tokens.rs | 1 + crates/rust-analyzer/src/to_proto.rs | 1 + 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index b0cfdd8b7..26118929b 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -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 => (), diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index 93db79b89..04540813c 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs @@ -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", } } diff --git a/crates/rust-analyzer/src/semantic_tokens.rs b/crates/rust-analyzer/src/semantic_tokens.rs index a3c5e9ccf..2dc8a42f1 100644 --- a/crates/rust-analyzer/src/semantic_tokens.rs +++ b/crates/rust-analyzer/src/semantic_tokens.rs @@ -88,6 +88,7 @@ define_semantic_token_modifiers![ (CONSUMING, "consuming"), (UNSAFE, "unsafe"), (ATTRIBUTE_MODIFIER, "attribute"), + (TRAIT_MODIFIER, "trait"), (CALLABLE, "callable"), (INTRA_DOC_LINK, "intraDocLink"), ]; diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index e297a72e6..c3820944b 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -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; -- cgit v1.2.3