diff options
author | Jeremy Kolb <[email protected]> | 2020-02-25 02:17:20 +0000 |
---|---|---|
committer | Jeremy Kolb <[email protected]> | 2020-02-25 02:17:20 +0000 |
commit | 17ffdf9c27a6bb5cf5d30ad6a677390609fcf861 (patch) | |
tree | 9783a59c97d1800fa1ed82eff4d39353c701b8c0 | |
parent | 9f0cfb7ad2120514ca8ffd21e08e3ddd0bfb34e9 (diff) |
Add docs
-rw-r--r-- | crates/rust-analyzer/src/semantic_tokens.rs | 8 |
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 | |||
1 | use lsp_types::{Range, SemanticToken, SemanticTokenModifier, SemanticTokenType}; | 3 | use lsp_types::{Range, SemanticToken, SemanticTokenModifier, SemanticTokenType}; |
2 | 4 | ||
3 | const SUPPORTED_TYPES: &[SemanticTokenType] = &[ | 5 | const 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 | ||
39 | pub(crate) fn supported_token_types() -> &'static [SemanticTokenType] { | 42 | pub(crate) fn supported_token_types() -> &'static [SemanticTokenType] { |
40 | SUPPORTED_TYPES | 43 | SUPPORTED_TYPES |
41 | } | 44 | } |
42 | 45 | ||
46 | /// Token modifiers that the server supports | ||
43 | pub(crate) fn supported_token_modifiers() -> &'static [SemanticTokenModifier] { | 47 | pub(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)] |
48 | pub(crate) struct SemanticTokensBuilder { | 55 | pub(crate) struct SemanticTokensBuilder { |
49 | prev_line: u32, | 56 | prev_line: u32, |
@@ -52,6 +59,7 @@ pub(crate) struct SemanticTokensBuilder { | |||
52 | } | 59 | } |
53 | 60 | ||
54 | impl SemanticTokensBuilder { | 61 | impl 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; |