mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Add self keyword semantic token type
This commit is contained in:
parent
1527feb744
commit
c2358365ad
6 changed files with 14 additions and 4 deletions
|
@ -35,12 +35,12 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||||
}
|
}
|
||||||
|
|
||||||
<span class="keyword">trait</span> <span class="trait declaration">Bar</span> {
|
<span class="keyword">trait</span> <span class="trait declaration">Bar</span> {
|
||||||
<span class="keyword">fn</span> <span class="function declaration">bar</span>(&<span class="keyword">self</span>) -> <span class="builtin_type">i32</span>;
|
<span class="keyword">fn</span> <span class="function declaration">bar</span>(&<span class="self_keyword">self</span>) -> <span class="builtin_type">i32</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
<span class="keyword">impl</span> <span class="trait">Bar</span> <span class="keyword">for</span> <span class="struct">Foo</span> {
|
<span class="keyword">impl</span> <span class="trait">Bar</span> <span class="keyword">for</span> <span class="struct">Foo</span> {
|
||||||
<span class="keyword">fn</span> <span class="function declaration">bar</span>(&<span class="keyword">self</span>) -> <span class="builtin_type">i32</span> {
|
<span class="keyword">fn</span> <span class="function declaration">bar</span>(&<span class="self_keyword">self</span>) -> <span class="builtin_type">i32</span> {
|
||||||
<span class="keyword">self</span>.<span class="field">x</span>
|
<span class="self_keyword">self</span>.<span class="field">x</span>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||||
<span class="keyword">use</span> <span class="enum">Option</span>::*;
|
<span class="keyword">use</span> <span class="enum">Option</span>::*;
|
||||||
|
|
||||||
<span class="keyword">impl</span><<span class="type_param declaration">T</span>> <span class="enum">Option</span><<span class="type_param">T</span>> {
|
<span class="keyword">impl</span><<span class="type_param declaration">T</span>> <span class="enum">Option</span><<span class="type_param">T</span>> {
|
||||||
<span class="keyword">fn</span> <span class="function declaration">and</span><<span class="type_param declaration">U</span>>(<span class="keyword">self</span>, <span class="variable declaration">other</span>: <span class="enum">Option</span><<span class="type_param">U</span>>) -> <span class="enum">Option</span><(<span class="type_param">T</span>, <span class="type_param">U</span>)> {
|
<span class="keyword">fn</span> <span class="function declaration">and</span><<span class="type_param declaration">U</span>>(<span class="self_keyword">self</span>, <span class="variable declaration">other</span>: <span class="enum">Option</span><<span class="type_param">U</span>>) -> <span class="enum">Option</span><(<span class="type_param">T</span>, <span class="type_param">U</span>)> {
|
||||||
<span class="keyword control">match</span> <span class="variable">other</span> {
|
<span class="keyword control">match</span> <span class="variable">other</span> {
|
||||||
<span class="enum_variant">None</span> => <span class="macro">unimplemented!</span>(),
|
<span class="enum_variant">None</span> => <span class="macro">unimplemented!</span>(),
|
||||||
<span class="variable declaration">Nope</span> => <span class="variable">Nope</span>,
|
<span class="variable declaration">Nope</span> => <span class="variable">Nope</span>,
|
||||||
|
|
|
@ -414,6 +414,7 @@ fn highlight_element(
|
||||||
T![for] if !is_child_of_impl(element) => h | HighlightModifier::ControlFlow,
|
T![for] if !is_child_of_impl(element) => h | HighlightModifier::ControlFlow,
|
||||||
T![unsafe] => h | HighlightModifier::Unsafe,
|
T![unsafe] => h | HighlightModifier::Unsafe,
|
||||||
T![true] | T![false] => HighlightTag::BoolLiteral.into(),
|
T![true] | T![false] => HighlightTag::BoolLiteral.into(),
|
||||||
|
T![self] => HighlightTag::SelfKeyword.into(),
|
||||||
_ => h,
|
_ => h,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ pub enum HighlightTag {
|
||||||
Macro,
|
Macro,
|
||||||
Module,
|
Module,
|
||||||
NumericLiteral,
|
NumericLiteral,
|
||||||
|
SelfKeyword,
|
||||||
SelfType,
|
SelfType,
|
||||||
Static,
|
Static,
|
||||||
StringLiteral,
|
StringLiteral,
|
||||||
|
@ -76,6 +77,7 @@ impl HighlightTag {
|
||||||
HighlightTag::Macro => "macro",
|
HighlightTag::Macro => "macro",
|
||||||
HighlightTag::Module => "module",
|
HighlightTag::Module => "module",
|
||||||
HighlightTag::NumericLiteral => "numeric_literal",
|
HighlightTag::NumericLiteral => "numeric_literal",
|
||||||
|
HighlightTag::SelfKeyword => "self_keyword",
|
||||||
HighlightTag::SelfType => "self_type",
|
HighlightTag::SelfType => "self_type",
|
||||||
HighlightTag::Static => "static",
|
HighlightTag::Static => "static",
|
||||||
HighlightTag::StringLiteral => "string_literal",
|
HighlightTag::StringLiteral => "string_literal",
|
||||||
|
|
|
@ -40,6 +40,7 @@ define_semantic_token_types![
|
||||||
(BUILTIN_TYPE, "builtinType"),
|
(BUILTIN_TYPE, "builtinType"),
|
||||||
(ENUM_MEMBER, "enumMember"),
|
(ENUM_MEMBER, "enumMember"),
|
||||||
(LIFETIME, "lifetime"),
|
(LIFETIME, "lifetime"),
|
||||||
|
(SELF_KEYWORD, "selfKeyword"),
|
||||||
(TYPE_ALIAS, "typeAlias"),
|
(TYPE_ALIAS, "typeAlias"),
|
||||||
(UNION, "union"),
|
(UNION, "union"),
|
||||||
(UNRESOLVED_REFERENCE, "unresolvedReference"),
|
(UNRESOLVED_REFERENCE, "unresolvedReference"),
|
||||||
|
|
|
@ -274,6 +274,7 @@ fn semantic_token_type_and_modifiers(
|
||||||
HighlightTag::TypeAlias => semantic_tokens::TYPE_ALIAS,
|
HighlightTag::TypeAlias => semantic_tokens::TYPE_ALIAS,
|
||||||
HighlightTag::Trait => lsp_types::SemanticTokenType::INTERFACE,
|
HighlightTag::Trait => lsp_types::SemanticTokenType::INTERFACE,
|
||||||
HighlightTag::BuiltinType => semantic_tokens::BUILTIN_TYPE,
|
HighlightTag::BuiltinType => semantic_tokens::BUILTIN_TYPE,
|
||||||
|
HighlightTag::SelfKeyword => semantic_tokens::SELF_KEYWORD,
|
||||||
HighlightTag::SelfType => lsp_types::SemanticTokenType::TYPE,
|
HighlightTag::SelfType => lsp_types::SemanticTokenType::TYPE,
|
||||||
HighlightTag::Field => lsp_types::SemanticTokenType::PROPERTY,
|
HighlightTag::Field => lsp_types::SemanticTokenType::PROPERTY,
|
||||||
HighlightTag::Function => lsp_types::SemanticTokenType::FUNCTION,
|
HighlightTag::Function => lsp_types::SemanticTokenType::FUNCTION,
|
||||||
|
|
|
@ -595,6 +595,11 @@
|
||||||
"id": "lifetime",
|
"id": "lifetime",
|
||||||
"description": "Style for lifetimes"
|
"description": "Style for lifetimes"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "selfKeyword",
|
||||||
|
"description": "Style for the self keyword",
|
||||||
|
"superType": "keyword"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "typeAlias",
|
"id": "typeAlias",
|
||||||
"description": "Style for type aliases",
|
"description": "Style for type aliases",
|
||||||
|
|
Loading…
Reference in a new issue