Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | crates/ide/src/syntax_highlighting.rs | 1 | ||||
| -rw-r--r-- | crates/ide/src/syntax_highlighting/highlight.rs | 1 | ||||
| -rw-r--r-- | crates/ide/src/syntax_highlighting/tags.rs | 1 | ||||
| -rw-r--r-- | crates/ide/src/syntax_highlighting/test_data/highlight_general.html | 6 | ||||
| -rw-r--r-- | crates/ide_completion/src/item.rs | 1 | ||||
| -rw-r--r-- | crates/ide_db/src/lib.rs | 1 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/semantic_tokens.rs | 1 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/to_proto.rs | 6 | ||||
| -rw-r--r-- | editors/code/package.json | 5 |
9 files changed, 19 insertions, 4 deletions
diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index bd6431da81..968aa33116 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -118,6 +118,7 @@ pub struct HlRange { // parameter:: Emitted for non-self function parameters. // property:: Emitted for struct and union fields. // selfKeyword:: Emitted for the self function parameter and self path-specifier. +// selfTypeKeyword:: Emitted for the Self type parameter. // toolModule:: Emitted for tool modules. // typeParameter:: Emitted for type parameters. // unresolvedReference:: Emitted for unresolved references, names that rust-analyzer can't find the definition of. diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 8ad27b1fdc..bf532b5bb2 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -190,6 +190,7 @@ fn keyword( T![for] if parent_matches::<ast::ForExpr>(&token) => h | HlMod::ControlFlow, T![unsafe] => h | HlMod::Unsafe, T![true] | T![false] => HlTag::BoolLiteral.into(), + T![Self] => return Some(HlTag::Symbol(SymbolKind::SelfType).into()), // crate is handled just as a token if it's in an `extern crate` T![crate] if parent_matches::<ast::ExternCrate>(&token) => h, // self, crate and super are handled as either a Name or NameRef already, unless they diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index bdf484e01f..cb9d36f830 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs @@ -141,6 +141,7 @@ impl HlTag { SymbolKind::Macro => "macro", SymbolKind::Module => "module", SymbolKind::SelfParam => "self_keyword", + SymbolKind::SelfType => "self_type_keyword", SymbolKind::Static => "static", SymbolKind::Struct => "struct", SymbolKind::ToolModule => "tool_module", 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 8501e0ffe5..27e3e57065 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_general.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_general.html @@ -59,11 +59,11 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd <span class="field declaration">x</span><span class="colon">:</span> <span class="builtin_type">u32</span><span class="comma">,</span> <span class="brace">}</span> -<span class="keyword">trait</span> <span class="trait declaration">Bar</span> <span class="keyword">where</span> <span class="keyword">Self</span><span class="colon">:</span> <span class="brace">{</span> +<span class="keyword">trait</span> <span class="trait declaration">Bar</span> <span class="keyword">where</span> <span class="self_type_keyword">Self</span><span class="colon">:</span> <span class="brace">{</span> <span class="keyword">fn</span> <span class="function associated declaration reference trait">bar</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span><span class="semicolon">;</span> <span class="brace">}</span> -<span class="keyword">impl</span> <span class="trait">Bar</span> <span class="keyword">for</span> <span class="struct">Foo</span> <span class="keyword">where</span> <span class="keyword">Self</span><span class="colon">:</span> <span class="brace">{</span> +<span class="keyword">impl</span> <span class="trait">Bar</span> <span class="keyword">for</span> <span class="struct">Foo</span> <span class="keyword">where</span> <span class="self_type_keyword">Self</span><span class="colon">:</span> <span class="brace">{</span> <span class="keyword">fn</span> <span class="function associated declaration reference trait">bar</span><span class="parenthesis">(</span><span class="operator">&</span><span class="self_keyword declaration reference">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">i32</span> <span class="brace">{</span> <span class="self_keyword reference">self</span><span class="operator">.</span><span class="field">x</span> <span class="brace">}</span> @@ -210,7 +210,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd <span class="keyword">impl</span> <span class="enum public">Bool</span> <span class="brace">{</span> <span class="keyword">pub</span> <span class="keyword">const</span> <span class="keyword">fn</span> <span class="function associated consuming declaration public">to_primitive</span><span class="parenthesis">(</span><span class="self_keyword declaration">self</span><span class="parenthesis">)</span> <span class="operator">-></span> <span class="builtin_type">bool</span> <span class="brace">{</span> - <span class="unresolved_reference">matches</span><span class="macro_bang">!</span><span class="parenthesis">(</span><span class="keyword">self</span><span class="comma">,</span> <span class="keyword">Self</span><span class="colon">:</span><span class="colon">:</span>True<span class="parenthesis">)</span> + <span class="unresolved_reference">matches</span><span class="macro_bang">!</span><span class="parenthesis">(</span><span class="keyword">self</span><span class="comma">,</span> <span class="self_type_keyword">Self</span><span class="colon">:</span><span class="colon">:</span>True<span class="parenthesis">)</span> <span class="brace">}</span> <span class="brace">}</span> <span class="keyword">const</span> <span class="constant 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="function associated consuming public">to_primitive</span><span class="parenthesis">(</span><span class="parenthesis">)</span><span class="semicolon">;</span> diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs index acaf17c255..32b14764a1 100644 --- a/crates/ide_completion/src/item.rs +++ b/crates/ide_completion/src/item.rs @@ -260,6 +260,7 @@ impl CompletionItemKind { SymbolKind::Macro => "ma", SymbolKind::Module => "md", SymbolKind::SelfParam => "sp", + SymbolKind::SelfType => "sy", SymbolKind::Static => "sc", SymbolKind::Struct => "st", SymbolKind::ToolModule => "tm", diff --git a/crates/ide_db/src/lib.rs b/crates/ide_db/src/lib.rs index 602eaf0de5..3f64c0a124 100644 --- a/crates/ide_db/src/lib.rs +++ b/crates/ide_db/src/lib.rs @@ -163,6 +163,7 @@ pub enum SymbolKind { Macro, Module, SelfParam, + SelfType, Static, Struct, ToolModule, diff --git a/crates/rust-analyzer/src/semantic_tokens.rs b/crates/rust-analyzer/src/semantic_tokens.rs index c6322327a5..5fb945ea98 100644 --- a/crates/rust-analyzer/src/semantic_tokens.rs +++ b/crates/rust-analyzer/src/semantic_tokens.rs @@ -66,6 +66,7 @@ define_semantic_token_types![ (PARENTHESIS, "parenthesis"), (PUNCTUATION, "punctuation"), (SELF_KEYWORD, "selfKeyword"), + (SELF_TYPE_KEYWORD, "selfTypeKeyword"), (SEMICOLON, "semicolon"), (TYPE_ALIAS, "typeAlias"), (TOOL_MODULE, "toolModule"), diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index f0de166d8b..4a2b3a1b47 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -55,7 +55,9 @@ pub(crate) fn symbol_kind(symbol_kind: SymbolKind) -> lsp_types::SymbolKind { | SymbolKind::Attribute | SymbolKind::Derive => lsp_types::SymbolKind::FUNCTION, SymbolKind::Module | SymbolKind::ToolModule => lsp_types::SymbolKind::MODULE, - SymbolKind::TypeAlias | SymbolKind::TypeParam => lsp_types::SymbolKind::TYPE_PARAMETER, + SymbolKind::TypeAlias | SymbolKind::TypeParam | SymbolKind::SelfType => { + lsp_types::SymbolKind::TYPE_PARAMETER + } SymbolKind::Field => lsp_types::SymbolKind::FIELD, SymbolKind::Static => lsp_types::SymbolKind::CONSTANT, SymbolKind::Const => lsp_types::SymbolKind::CONSTANT, @@ -124,6 +126,7 @@ pub(crate) fn completion_item_kind( SymbolKind::Macro => lsp_types::CompletionItemKind::FUNCTION, SymbolKind::Module => lsp_types::CompletionItemKind::MODULE, SymbolKind::SelfParam => lsp_types::CompletionItemKind::VALUE, + SymbolKind::SelfType => lsp_types::CompletionItemKind::TYPE_PARAMETER, SymbolKind::Static => lsp_types::CompletionItemKind::VALUE, SymbolKind::Struct => lsp_types::CompletionItemKind::STRUCT, SymbolKind::Trait => lsp_types::CompletionItemKind::INTERFACE, @@ -483,6 +486,7 @@ fn semantic_token_type_and_modifiers( SymbolKind::Label => semantic_tokens::LABEL, SymbolKind::ValueParam => lsp_types::SemanticTokenType::PARAMETER, SymbolKind::SelfParam => semantic_tokens::SELF_KEYWORD, + SymbolKind::SelfType => semantic_tokens::SELF_TYPE_KEYWORD, SymbolKind::Local => lsp_types::SemanticTokenType::VARIABLE, SymbolKind::Function => { if highlight.mods.contains(HlMod::Associated) { diff --git a/editors/code/package.json b/editors/code/package.json index 1252752a9a..fb519be461 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -1295,6 +1295,11 @@ "superType": "keyword" }, { + "id": "selfTypeKeyword", + "description": "Style for the self type keyword", + "superType": "typeParameter" + }, + { "id": "semicolon", "description": "Style for ;", "superType": "punctuation" |