Skip to content

Commit b98c119

Browse files
committed
Apply async semantic token modifier to async/await keywords
Only async semantic token modifier
1 parent 9803a9a commit b98c119

File tree

5 files changed

+17
-0
lines changed

5 files changed

+17
-0
lines changed

crates/hir/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,10 @@ impl Function {
873873
db.function_data(self.id).is_unsafe()
874874
}
875875

876+
pub fn is_async(self, db: &dyn HirDatabase) -> bool {
877+
db.function_data(self.id).is_async()
878+
}
879+
876880
pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) {
877881
let krate = self.module(db).id.krate();
878882
hir_def::diagnostics::validate_body(db.upcast(), self.id.into(), sink);

crates/ide/src/syntax_highlighting/highlight.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ pub(super) fn element(
255255
})
256256
.map(|modifier| h | modifier)
257257
.unwrap_or(h),
258+
T![async] | T![await] => h | HlMod::Async,
258259
_ => h,
259260
}
260261
}
@@ -310,6 +311,9 @@ fn highlight_def(db: &RootDatabase, def: Definition) -> Highlight {
310311
if func.is_unsafe(db) {
311312
h |= HlMod::Unsafe;
312313
}
314+
if func.is_async(db) {
315+
h |= HlMod::Async;
316+
}
313317
return h;
314318
}
315319
hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HlTag::Symbol(SymbolKind::Struct),
@@ -409,6 +413,9 @@ fn highlight_method_call(
409413
if func.is_unsafe(sema.db) || sema.is_unsafe_method_call(&method_call) {
410414
h |= HlMod::Unsafe;
411415
}
416+
if func.is_async(sema.db) {
417+
h |= HlMod::Async;
418+
}
412419
if func.as_assoc_item(sema.db).and_then(|it| it.containing_trait(sema.db)).is_some() {
413420
h |= HlMod::Trait
414421
}

crates/ide/src/syntax_highlighting/tags.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ pub enum HlMod {
6565
Static,
6666
/// Used for items in traits and trait impls.
6767
Trait,
68+
/// Used with keywords like `async` and `await`.
69+
Async,
6870
// Keep this last!
6971
/// Used for unsafe functions, mutable statics, union accesses and unsafe operations.
7072
Unsafe,
@@ -186,6 +188,7 @@ impl HlMod {
186188
HlMod::Mutable,
187189
HlMod::Static,
188190
HlMod::Trait,
191+
HlMod::Async,
189192
HlMod::Unsafe,
190193
];
191194

@@ -203,6 +206,7 @@ impl HlMod {
203206
HlMod::Mutable => "mutable",
204207
HlMod::Static => "static",
205208
HlMod::Trait => "trait",
209+
HlMod::Async => "async",
206210
HlMod::Unsafe => "unsafe",
207211
}
208212
}

crates/rust-analyzer/src/semantic_tokens.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ define_semantic_token_modifiers![
9191
(INJECTED, "injected"),
9292
(MUTABLE, "mutable"),
9393
(CONSUMING, "consuming"),
94+
(ASYNC, "async"),
9495
(UNSAFE, "unsafe"),
9596
(ATTRIBUTE_MODIFIER, "attribute"),
9697
(TRAIT_MODIFIER, "trait"),

crates/rust-analyzer/src/to_proto.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ fn semantic_token_type_and_modifiers(
496496
HlMod::ControlFlow => semantic_tokens::CONTROL_FLOW,
497497
HlMod::Mutable => semantic_tokens::MUTABLE,
498498
HlMod::Consuming => semantic_tokens::CONSUMING,
499+
HlMod::Async => semantic_tokens::ASYNC,
499500
HlMod::Unsafe => semantic_tokens::UNSAFE,
500501
HlMod::Callable => semantic_tokens::CALLABLE,
501502
HlMod::Static => lsp_types::SemanticTokenModifier::STATIC,

0 commit comments

Comments
 (0)