mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-26 11:55:04 +00:00
Fix highlighting of Self
This commit is contained in:
parent
c0d6471143
commit
5c0aee013e
9 changed files with 19 additions and 4 deletions
|
@ -118,6 +118,7 @@ pub struct HlRange {
|
||||||
// parameter:: Emitted for non-self function parameters.
|
// parameter:: Emitted for non-self function parameters.
|
||||||
// property:: Emitted for struct and union fields.
|
// property:: Emitted for struct and union fields.
|
||||||
// selfKeyword:: Emitted for the self function parameter and self path-specifier.
|
// selfKeyword:: Emitted for the self function parameter and self path-specifier.
|
||||||
|
// selfTypeKeyword:: Emitted for the Self type parameter.
|
||||||
// toolModule:: Emitted for tool modules.
|
// toolModule:: Emitted for tool modules.
|
||||||
// typeParameter:: Emitted for type parameters.
|
// typeParameter:: Emitted for type parameters.
|
||||||
// unresolvedReference:: Emitted for unresolved references, names that rust-analyzer can't find the definition of.
|
// unresolvedReference:: Emitted for unresolved references, names that rust-analyzer can't find the definition of.
|
||||||
|
|
|
@ -190,6 +190,7 @@ fn keyword(
|
||||||
T![for] if parent_matches::<ast::ForExpr>(&token) => h | HlMod::ControlFlow,
|
T![for] if parent_matches::<ast::ForExpr>(&token) => h | HlMod::ControlFlow,
|
||||||
T![unsafe] => h | HlMod::Unsafe,
|
T![unsafe] => h | HlMod::Unsafe,
|
||||||
T![true] | T![false] => HlTag::BoolLiteral.into(),
|
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`
|
// crate is handled just as a token if it's in an `extern crate`
|
||||||
T![crate] if parent_matches::<ast::ExternCrate>(&token) => h,
|
T![crate] if parent_matches::<ast::ExternCrate>(&token) => h,
|
||||||
// self, crate and super are handled as either a Name or NameRef already, unless they
|
// self, crate and super are handled as either a Name or NameRef already, unless they
|
||||||
|
|
|
@ -141,6 +141,7 @@ impl HlTag {
|
||||||
SymbolKind::Macro => "macro",
|
SymbolKind::Macro => "macro",
|
||||||
SymbolKind::Module => "module",
|
SymbolKind::Module => "module",
|
||||||
SymbolKind::SelfParam => "self_keyword",
|
SymbolKind::SelfParam => "self_keyword",
|
||||||
|
SymbolKind::SelfType => "self_type_keyword",
|
||||||
SymbolKind::Static => "static",
|
SymbolKind::Static => "static",
|
||||||
SymbolKind::Struct => "struct",
|
SymbolKind::Struct => "struct",
|
||||||
SymbolKind::ToolModule => "tool_module",
|
SymbolKind::ToolModule => "tool_module",
|
||||||
|
|
|
@ -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="field declaration">x</span><span class="colon">:</span> <span class="builtin_type">u32</span><span class="comma">,</span>
|
||||||
<span class="brace">}</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="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="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="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="self_keyword reference">self</span><span class="operator">.</span><span class="field">x</span>
|
||||||
<span class="brace">}</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">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="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="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>
|
<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>
|
||||||
|
|
|
@ -260,6 +260,7 @@ impl CompletionItemKind {
|
||||||
SymbolKind::Macro => "ma",
|
SymbolKind::Macro => "ma",
|
||||||
SymbolKind::Module => "md",
|
SymbolKind::Module => "md",
|
||||||
SymbolKind::SelfParam => "sp",
|
SymbolKind::SelfParam => "sp",
|
||||||
|
SymbolKind::SelfType => "sy",
|
||||||
SymbolKind::Static => "sc",
|
SymbolKind::Static => "sc",
|
||||||
SymbolKind::Struct => "st",
|
SymbolKind::Struct => "st",
|
||||||
SymbolKind::ToolModule => "tm",
|
SymbolKind::ToolModule => "tm",
|
||||||
|
|
|
@ -163,6 +163,7 @@ pub enum SymbolKind {
|
||||||
Macro,
|
Macro,
|
||||||
Module,
|
Module,
|
||||||
SelfParam,
|
SelfParam,
|
||||||
|
SelfType,
|
||||||
Static,
|
Static,
|
||||||
Struct,
|
Struct,
|
||||||
ToolModule,
|
ToolModule,
|
||||||
|
|
|
@ -66,6 +66,7 @@ define_semantic_token_types![
|
||||||
(PARENTHESIS, "parenthesis"),
|
(PARENTHESIS, "parenthesis"),
|
||||||
(PUNCTUATION, "punctuation"),
|
(PUNCTUATION, "punctuation"),
|
||||||
(SELF_KEYWORD, "selfKeyword"),
|
(SELF_KEYWORD, "selfKeyword"),
|
||||||
|
(SELF_TYPE_KEYWORD, "selfTypeKeyword"),
|
||||||
(SEMICOLON, "semicolon"),
|
(SEMICOLON, "semicolon"),
|
||||||
(TYPE_ALIAS, "typeAlias"),
|
(TYPE_ALIAS, "typeAlias"),
|
||||||
(TOOL_MODULE, "toolModule"),
|
(TOOL_MODULE, "toolModule"),
|
||||||
|
|
|
@ -55,7 +55,9 @@ pub(crate) fn symbol_kind(symbol_kind: SymbolKind) -> lsp_types::SymbolKind {
|
||||||
| SymbolKind::Attribute
|
| SymbolKind::Attribute
|
||||||
| SymbolKind::Derive => lsp_types::SymbolKind::FUNCTION,
|
| SymbolKind::Derive => lsp_types::SymbolKind::FUNCTION,
|
||||||
SymbolKind::Module | SymbolKind::ToolModule => lsp_types::SymbolKind::MODULE,
|
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::Field => lsp_types::SymbolKind::FIELD,
|
||||||
SymbolKind::Static => lsp_types::SymbolKind::CONSTANT,
|
SymbolKind::Static => lsp_types::SymbolKind::CONSTANT,
|
||||||
SymbolKind::Const => 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::Macro => lsp_types::CompletionItemKind::FUNCTION,
|
||||||
SymbolKind::Module => lsp_types::CompletionItemKind::MODULE,
|
SymbolKind::Module => lsp_types::CompletionItemKind::MODULE,
|
||||||
SymbolKind::SelfParam => lsp_types::CompletionItemKind::VALUE,
|
SymbolKind::SelfParam => lsp_types::CompletionItemKind::VALUE,
|
||||||
|
SymbolKind::SelfType => lsp_types::CompletionItemKind::TYPE_PARAMETER,
|
||||||
SymbolKind::Static => lsp_types::CompletionItemKind::VALUE,
|
SymbolKind::Static => lsp_types::CompletionItemKind::VALUE,
|
||||||
SymbolKind::Struct => lsp_types::CompletionItemKind::STRUCT,
|
SymbolKind::Struct => lsp_types::CompletionItemKind::STRUCT,
|
||||||
SymbolKind::Trait => lsp_types::CompletionItemKind::INTERFACE,
|
SymbolKind::Trait => lsp_types::CompletionItemKind::INTERFACE,
|
||||||
|
@ -483,6 +486,7 @@ fn semantic_token_type_and_modifiers(
|
||||||
SymbolKind::Label => semantic_tokens::LABEL,
|
SymbolKind::Label => semantic_tokens::LABEL,
|
||||||
SymbolKind::ValueParam => lsp_types::SemanticTokenType::PARAMETER,
|
SymbolKind::ValueParam => lsp_types::SemanticTokenType::PARAMETER,
|
||||||
SymbolKind::SelfParam => semantic_tokens::SELF_KEYWORD,
|
SymbolKind::SelfParam => semantic_tokens::SELF_KEYWORD,
|
||||||
|
SymbolKind::SelfType => semantic_tokens::SELF_TYPE_KEYWORD,
|
||||||
SymbolKind::Local => lsp_types::SemanticTokenType::VARIABLE,
|
SymbolKind::Local => lsp_types::SemanticTokenType::VARIABLE,
|
||||||
SymbolKind::Function => {
|
SymbolKind::Function => {
|
||||||
if highlight.mods.contains(HlMod::Associated) {
|
if highlight.mods.contains(HlMod::Associated) {
|
||||||
|
|
|
@ -1294,6 +1294,11 @@
|
||||||
"description": "Style for the self keyword",
|
"description": "Style for the self keyword",
|
||||||
"superType": "keyword"
|
"superType": "keyword"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "selfTypeKeyword",
|
||||||
|
"description": "Style for the self type keyword",
|
||||||
|
"superType": "typeParameter"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "semicolon",
|
"id": "semicolon",
|
||||||
"description": "Style for ;",
|
"description": "Style for ;",
|
||||||
|
|
Loading…
Reference in a new issue