diff options
| author | bors <bors@rust-lang.org> | 2024-04-15 15:19:56 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-04-15 15:19:56 +0000 |
| commit | b223860c0e4635e7b9788866422c5f5514518cf7 (patch) | |
| tree | 8ea2796f3129625b50779bdbd93d277ab6ad5bab | |
| parent | af728741de6ad74517f34053efae864d7d75ac5d (diff) | |
| parent | 597c293a69de33cbfa392c09a9b89a3211917fa3 (diff) | |
| download | rust-b223860c0e4635e7b9788866422c5f5514518cf7.tar.gz rust-b223860c0e4635e7b9788866422c5f5514518cf7.zip | |
Auto merge of #17074 - Veykril:hl, r=Veykril
Add Static and Const highlighting token types
| -rw-r--r-- | crates/ide/src/syntax_highlighting/highlight.rs | 1 | ||||
| -rw-r--r-- | crates/ide/src/syntax_highlighting/tags.rs | 4 | ||||
| -rw-r--r-- | crates/ide/src/syntax_highlighting/test_data/highlight_general.html | 2 | ||||
| -rw-r--r-- | crates/ide/src/syntax_highlighting/tests.rs | 2 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/lsp/semantic_tokens.rs | 37 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/lsp/to_proto.rs | 160 | ||||
| -rw-r--r-- | editors/code/package.json | 38 |
7 files changed, 142 insertions, 102 deletions
diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index e7346cbb992..a72f505eb85 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -444,7 +444,6 @@ pub(super) fn highlight_def( Definition::Variant(_) => Highlight::new(HlTag::Symbol(SymbolKind::Variant)), Definition::Const(konst) => { let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Const)) | HlMod::Const; - if let Some(item) = konst.as_assoc_item(db) { h |= HlMod::Associated; h |= HlMod::Static; diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index d9225fedeae..e329023606a 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs @@ -77,6 +77,7 @@ pub enum HlMod { Library, /// Used to differentiate individual elements within macro calls. Macro, + /// Used to differentiate individual elements within proc-macro calls. ProcMacro, /// Mutable binding. Mutable, @@ -225,8 +226,8 @@ impl HlMod { HlMod::IntraDocLink, HlMod::Library, HlMod::Macro, - HlMod::ProcMacro, HlMod::Mutable, + HlMod::ProcMacro, HlMod::Public, HlMod::Reference, HlMod::Static, @@ -262,6 +263,7 @@ impl HlMod { } fn mask(self) -> u32 { + debug_assert!(Self::ALL.len() <= 32, "HlMod::mask is not enough to cover all variants"); 1 << (self as u32) } } diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_general.html b/crates/ide/src/syntax_highlighting/test_data/highlight_general.html index 7ba1194d675..5234d362c26 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_general.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_general.html @@ -218,7 +218,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd <span class="bool_literal">true</span> <span class="brace">}</span> <span class="brace">}</span> -<span class="keyword const">const</span> <span class="constant const declaration">USAGE_OF_BOOL</span><span class="colon">:</span><span class="builtin_type">bool</span> <span class="operator">=</span> <span class="enum public">Bool</span><span class="operator">::</span><span class="enum_variant public">True</span><span class="operator">.</span><span class="method consuming public">to_primitive</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> +<span class="keyword const">const</span> <span class="constant const declaration">USAGE_OF_BOOL</span><span class="colon">:</span> <span class="builtin_type">bool</span> <span class="operator">=</span> <span class="enum public">Bool</span><span class="operator">::</span><span class="enum_variant public">True</span><span class="operator">.</span><span class="method consuming public">to_primitive</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> <span class="keyword">trait</span> <span class="trait declaration">Baz</span> <span class="brace">{</span> <span class="keyword">type</span> <span class="type_alias associated declaration static trait">Qux</span><span class="semicolon">;</span> diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index c2990fd76ea..901e41d27cd 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -300,7 +300,7 @@ impl Bool { true } } -const USAGE_OF_BOOL:bool = Bool::True.to_primitive(); +const USAGE_OF_BOOL: bool = Bool::True.to_primitive(); trait Baz { type Qux; diff --git a/crates/rust-analyzer/src/lsp/semantic_tokens.rs b/crates/rust-analyzer/src/lsp/semantic_tokens.rs index 3e00222b752..991c10743f7 100644 --- a/crates/rust-analyzer/src/lsp/semantic_tokens.rs +++ b/crates/rust-analyzer/src/lsp/semantic_tokens.rs @@ -17,15 +17,19 @@ macro_rules! define_semantic_token_types { } ) => { - $(pub(crate) const $standard: SemanticTokenType = SemanticTokenType::$standard;)* - $(pub(crate) const $custom: SemanticTokenType = SemanticTokenType::new($string);)* + pub(crate) mod types { + use super::SemanticTokenType; + $(pub(crate) const $standard: SemanticTokenType = SemanticTokenType::$standard;)* + $(pub(crate) const $custom: SemanticTokenType = SemanticTokenType::new($string);)* + } pub(crate) const SUPPORTED_TYPES: &[SemanticTokenType] = &[ $(SemanticTokenType::$standard,)* - $($custom),* + $(self::types::$custom),* ]; pub(crate) fn standard_fallback_type(token: SemanticTokenType) -> Option<SemanticTokenType> { + use self::types::*; $( if token == $custom { None $(.or(Some(SemanticTokenType::$fallback)))? @@ -61,39 +65,41 @@ define_semantic_token_types![ custom { (ANGLE, "angle"), (ARITHMETIC, "arithmetic") => OPERATOR, - (ATTRIBUTE, "attribute") => DECORATOR, (ATTRIBUTE_BRACKET, "attributeBracket") => DECORATOR, + (ATTRIBUTE, "attribute") => DECORATOR, (BITWISE, "bitwise") => OPERATOR, (BOOLEAN, "boolean"), (BRACE, "brace"), (BRACKET, "bracket"), (BUILTIN_ATTRIBUTE, "builtinAttribute") => DECORATOR, - (BUILTIN_TYPE, "builtinType"), + (BUILTIN_TYPE, "builtinType") => TYPE, (CHAR, "character") => STRING, (COLON, "colon"), (COMMA, "comma"), (COMPARISON, "comparison") => OPERATOR, (CONST_PARAMETER, "constParameter"), - (DERIVE, "derive") => DECORATOR, + (CONST, "const") => VARIABLE, (DERIVE_HELPER, "deriveHelper") => DECORATOR, + (DERIVE, "derive") => DECORATOR, (DOT, "dot"), (ESCAPE_SEQUENCE, "escapeSequence") => STRING, - (INVALID_ESCAPE_SEQUENCE, "invalidEscapeSequence") => STRING, (FORMAT_SPECIFIER, "formatSpecifier") => STRING, (GENERIC, "generic") => TYPE_PARAMETER, + (INVALID_ESCAPE_SEQUENCE, "invalidEscapeSequence") => STRING, (LABEL, "label"), (LIFETIME, "lifetime"), (LOGICAL, "logical") => OPERATOR, (MACRO_BANG, "macroBang") => MACRO, - (PROC_MACRO, "procMacro") => MACRO, (PARENTHESIS, "parenthesis"), + (PROC_MACRO, "procMacro") => MACRO, (PUNCTUATION, "punctuation"), (SELF_KEYWORD, "selfKeyword") => KEYWORD, (SELF_TYPE_KEYWORD, "selfTypeKeyword") => KEYWORD, (SEMICOLON, "semicolon"), - (TYPE_ALIAS, "typeAlias"), + (STATIC, "static") => VARIABLE, (TOOL_MODULE, "toolModule") => DECORATOR, - (UNION, "union"), + (TYPE_ALIAS, "typeAlias") => TYPE, + (UNION, "union") => TYPE, (UNRESOLVED_REFERENCE, "unresolvedReference"), } ]; @@ -112,13 +118,16 @@ macro_rules! define_semantic_token_modifiers { } ) => { + pub(crate) mod modifiers { + use super::SemanticTokenModifier; - $(pub(crate) const $standard: SemanticTokenModifier = SemanticTokenModifier::$standard;)* - $(pub(crate) const $custom: SemanticTokenModifier = SemanticTokenModifier::new($string);)* + $(pub(crate) const $standard: SemanticTokenModifier = SemanticTokenModifier::$standard;)* + $(pub(crate) const $custom: SemanticTokenModifier = SemanticTokenModifier::new($string);)* + } pub(crate) const SUPPORTED_MODIFIERS: &[SemanticTokenModifier] = &[ $(SemanticTokenModifier::$standard,)* - $($custom),* + $(self::modifiers::$custom),* ]; const LAST_STANDARD_MOD: usize = count_tts!($($standard)*); @@ -145,8 +154,8 @@ define_semantic_token_modifiers