From b98c119ba690afdcd21edb3b344834e42422df0a Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Fri, 14 May 2021 10:36:12 +0800 Subject: Apply async semantic token modifier to async/await keywords Only async semantic token modifier --- crates/ide/src/syntax_highlighting/highlight.rs | 7 +++++++ crates/ide/src/syntax_highlighting/tags.rs | 4 ++++ 2 files changed, 11 insertions(+) (limited to 'crates/ide') diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index b586dcc17..bea506544 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -255,6 +255,7 @@ pub(super) fn element( }) .map(|modifier| h | modifier) .unwrap_or(h), + T![async] | T![await] => h | HlMod::Async, _ => h, } } @@ -310,6 +311,9 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight { if func.is_unsafe(db) { h |= HlMod::Unsafe; } + if func.is_async(db) { + h |= HlMod::Async; + } return h; } hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HlTag::Symbol(SymbolKind::Struct), @@ -409,6 +413,9 @@ fn highlight_method_call( if func.is_unsafe(sema.db) || sema.is_unsafe_method_call(&method_call) { h |= HlMod::Unsafe; } + if func.is_async(sema.db) { + h |= HlMod::Async; + } if func.as_assoc_item(sema.db).and_then(|it| it.containing_trait(sema.db)).is_some() { h |= HlMod::Trait } diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index a304b3250..f4a2e7506 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs @@ -65,6 +65,8 @@ pub enum HlMod { Static, /// Used for items in traits and trait impls. Trait, + /// Used with keywords like `async` and `await`. + Async, // Keep this last! /// Used for unsafe functions, mutable statics, union accesses and unsafe operations. Unsafe, @@ -186,6 +188,7 @@ impl HlMod { HlMod::Mutable, HlMod::Static, HlMod::Trait, + HlMod::Async, HlMod::Unsafe, ]; @@ -203,6 +206,7 @@ impl HlMod { HlMod::Mutable => "mutable", HlMod::Static => "static", HlMod::Trait => "trait", + HlMod::Async => "async", HlMod::Unsafe => "unsafe", } } -- cgit v1.2.3