]> git.lizzy.rs Git - rust.git/commitdiff
Document semantic token modifiers
authorLukas Wirth <lukastw97@gmail.com>
Wed, 26 May 2021 11:29:00 +0000 (13:29 +0200)
committerLukas Wirth <lukastw97@gmail.com>
Wed, 26 May 2021 11:37:54 +0000 (13:37 +0200)
crates/ide/src/syntax_highlighting.rs
crates/ide/src/syntax_highlighting/tags.rs

index cf1a8bad7968009e750f33ecd3e20f7e77370edb..7f7f4d38af10d007d6995a337626c018fa36c2ea 100644 (file)
@@ -49,6 +49,30 @@ pub struct HlRange {
 // The general rule is that a reference to an entity gets colored the same way as the entity itself.
 // We also give special modifier for `mut` and `&mut` local variables.
 //
+// .Token Modifiers
+//
+// Token modifiers allow to style some elements in the source code more precisely.
+//
+// Rust-analyzer currently emits the following token modifiers:
+//
+// [horizontal]
+// associated:: Emitted for associated items.
+// async:: Emitted for async functions and the `async` and `await` keywords.
+// attribute:: Emitted for tokens inside attributes.
+// callable:: Emitted for locals whose types implements one of the `Fn*` traits.
+// consuming:: Emitted for locals that are being consumed when use in a function call.
+// controlFlow:: Emitted for control-flow related tokens, this includes the `?` operator.
+// declaration:: Emitted for names of definitions, like `foo` in `fn foo() {}`.
+// documentation:: Emitted for documentation comments.
+// injected:: Emitted for doc-string injected highlighting like rust source blocks in documentation.
+// intraDocLink:: Emitted for intra doc links in doc-strings.
+// library:: Emitted for items that are defined outside of the current crate.
+// mutable:: Emitted for mutable locals and statics.
+// static:: Emitted for "static" functions, also known as functions that do not take a `self` param.
+// trait:: Emitted for associated trait items.
+// unsafe:: Emitted for unsafe operations, like unsafe function calls, as well as the `unsafe` token.
+//
+//
 // image::https://user-images.githubusercontent.com/48062697/113164457-06cfb980-9239-11eb-819b-0f93e646acf8.png[]
 // image::https://user-images.githubusercontent.com/48062697/113187625-f7f50100-9250-11eb-825e-91c58f236071.png[]
 pub(crate) fn highlight(
index e94f17cd98b4e0e1a7f95f4a557a3e524d6cbf33..9d481deae344d016333dceb2354ebd42e24f2e1d 100644 (file)
@@ -37,6 +37,8 @@ pub enum HlTag {
     None,
 }
 
+// Don't forget to adjust the feature description in crates/ide/src/syntax_highlighting.rs.
+// And make sure to use the lsp strings used when converting to the protocol in crates\rust-analyzer\src\semantic_tokens.rs, not the names of the variants here.
 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
 #[repr(u8)]
 pub enum HlMod {