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 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'crates/ide/src/syntax_highlighting') 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", } } -- cgit v1.2.3