aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/semantic_tokens.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/crates/rust-analyzer/src/semantic_tokens.rs b/crates/rust-analyzer/src/semantic_tokens.rs
index f76605aaa..ad000a3ce 100644
--- a/crates/rust-analyzer/src/semantic_tokens.rs
+++ b/crates/rust-analyzer/src/semantic_tokens.rs
@@ -1,3 +1,5 @@
1//! Semantic Tokens helpers
2
1use lsp_types::{Range, SemanticToken, SemanticTokenModifier, SemanticTokenType}; 3use lsp_types::{Range, SemanticToken, SemanticTokenModifier, SemanticTokenType};
2 4
3const SUPPORTED_TYPES: &[SemanticTokenType] = &[ 5const SUPPORTED_TYPES: &[SemanticTokenType] = &[
@@ -36,14 +38,19 @@ const SUPPORTED_MODIFIERS: &[SemanticTokenModifier] = &[
36 SemanticTokenModifier::READONLY, 38 SemanticTokenModifier::READONLY,
37]; 39];
38 40
41/// Token types that the server supports
39pub(crate) fn supported_token_types() -> &'static [SemanticTokenType] { 42pub(crate) fn supported_token_types() -> &'static [SemanticTokenType] {
40 SUPPORTED_TYPES 43 SUPPORTED_TYPES
41} 44}
42 45
46/// Token modifiers that the server supports
43pub(crate) fn supported_token_modifiers() -> &'static [SemanticTokenModifier] { 47pub(crate) fn supported_token_modifiers() -> &'static [SemanticTokenModifier] {
44 SUPPORTED_MODIFIERS 48 SUPPORTED_MODIFIERS
45} 49}
46 50
51/// Tokens are encoded relative to each other.
52///
53/// This is a direct port of https://github.com/microsoft/vscode-languageserver-node/blob/f425af9de46a0187adb78ec8a46b9b2ce80c5412/server/src/sematicTokens.proposed.ts#L45
47#[derive(Default)] 54#[derive(Default)]
48pub(crate) struct SemanticTokensBuilder { 55pub(crate) struct SemanticTokensBuilder {
49 prev_line: u32, 56 prev_line: u32,
@@ -52,6 +59,7 @@ pub(crate) struct SemanticTokensBuilder {
52} 59}
53 60
54impl SemanticTokensBuilder { 61impl SemanticTokensBuilder {
62 /// Push a new token onto the builder
55 pub fn push(&mut self, range: Range, token_index: u32, modifier_bitset: u32) { 63 pub fn push(&mut self, range: Range, token_index: u32, modifier_bitset: u32) {
56 let mut push_line = range.start.line as u32; 64 let mut push_line = range.start.line as u32;
57 let mut push_char = range.start.character as u32; 65 let mut push_char = range.start.character as u32;