Skip to content

Commit f269fe7

Browse files
8024: Added the trait modifier for methods
method in impls and method calls will have trait modifier.
1 parent fd7c454 commit f269fe7

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

crates/ide/src/syntax_highlighting/highlight.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Computes color for a single element.
22
3-
use hir::{AsAssocItem, Semantics, VariantDef};
3+
use hir::{AsAssocItem, AssocItemContainer, Semantics, VariantDef};
44
use ide_db::{
55
defs::{Definition, NameClass, NameRefClass},
66
RootDatabase, SymbolKind,
@@ -275,6 +275,19 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
275275
hir::ModuleDef::Module(_) => HlTag::Symbol(SymbolKind::Module),
276276
hir::ModuleDef::Function(func) => {
277277
let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Function));
278+
if let Some(item) = func.as_assoc_item(db) {
279+
match item.container(db) {
280+
AssocItemContainer::Impl(i) => {
281+
if i.target_trait(db).is_some() {
282+
h |= HlMod::Trait;
283+
}
284+
}
285+
AssocItemContainer::Trait(_t) => {
286+
h |= HlMod::Trait;
287+
}
288+
}
289+
}
290+
278291
if func.as_assoc_item(db).is_some() {
279292
h |= HlMod::Associated;
280293
if func.self_param(db).is_none() {
@@ -362,6 +375,10 @@ fn highlight_method_call(
362375
if func.is_unsafe(sema.db) || sema.is_unsafe_method_call(&method_call) {
363376
h |= HlMod::Unsafe;
364377
}
378+
if let Some(_t) = func.as_assoc_item(sema.db)?.containing_trait(sema.db) {
379+
h |= HlMod::Trait
380+
}
381+
365382
if let Some(self_param) = func.self_param(sema.db) {
366383
match self_param.access(sema.db) {
367384
hir::Access::Shared => (),

crates/ide/src/syntax_highlighting/tags.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ pub enum HlMod {
5858
Associated,
5959
/// Used for intra doc links in doc injection.
6060
IntraDocLink,
61+
/// Used for trait items in impls.
62+
Trait,
6163

6264
/// Keep this last!
6365
Unsafe,
@@ -158,6 +160,7 @@ impl HlMod {
158160
HlMod::Callable,
159161
HlMod::Static,
160162
HlMod::Associated,
163+
HlMod::Trait,
161164
HlMod::Unsafe,
162165
];
163166

@@ -174,6 +177,7 @@ impl HlMod {
174177
HlMod::IntraDocLink => "intra_doc_link",
175178
HlMod::Mutable => "mutable",
176179
HlMod::Static => "static",
180+
HlMod::Trait => "trait",
177181
HlMod::Unsafe => "unsafe",
178182
}
179183
}

crates/rust-analyzer/src/semantic_tokens.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ define_semantic_token_modifiers![
8888
(CONSUMING, "consuming"),
8989
(UNSAFE, "unsafe"),
9090
(ATTRIBUTE_MODIFIER, "attribute"),
91+
(TRAIT_MODIFIER, "trait"),
9192
(CALLABLE, "callable"),
9293
(INTRA_DOC_LINK, "intraDocLink"),
9394
];

crates/rust-analyzer/src/to_proto.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ fn semantic_token_type_and_modifiers(
474474
HlMod::Callable => semantic_tokens::CALLABLE,
475475
HlMod::Static => lsp_types::SemanticTokenModifier::STATIC,
476476
HlMod::IntraDocLink => semantic_tokens::INTRA_DOC_LINK,
477+
HlMod::Trait => semantic_tokens::TRAIT_MODIFIER,
477478
HlMod::Associated => continue,
478479
};
479480
mods |= modifier;

0 commit comments

Comments
 (0)