3363: Cleanup highlighting tags r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-02-28 13:48:42 +00:00 committed by GitHub
commit 2995fd2c87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 236 additions and 161 deletions

View file

@ -3,70 +3,72 @@
body { margin: 0; }
pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
.comment { color: #7F9F7F; }
.string { color: #CC9393; }
.struct, .enum { color: #7CB8BB; }
.enum_variant { color: #BDE0F3; }
.string_literal { color: #CC9393; }
.field { color: #94BFF3; }
.function { color: #93E0E3; }
.parameter { color: #94BFF3; }
.text { color: #DCDCCC; }
.type { color: #7CB8BB; }
.type.builtin { color: #8CD0D3; }
.type.param { color: #20999D; }
.builtin_type { color: #8CD0D3; }
.type_param { color: #DFAF8F; }
.attribute { color: #94BFF3; }
.literal { color: #BFEBBF; }
.literal.numeric { color: #6A8759; }
.numeric_literal { color: #BFEBBF; }
.macro { color: #94BFF3; }
.module { color: #AFD8AF; }
.variable { color: #DCDCCC; }
.variable.mut { color: #DCDCCC; text-decoration: underline; }
.mutable { text-decoration: underline; }
.keyword { color: #F0DFAF; }
.keyword.unsafe { color: #DFAF8F; }
.keyword.control { color: #F0DFAF; font-weight: bold; }
.keyword { color: #F0DFAF; font-weight: bold; }
.keyword.unsafe { color: #BC8383; font-weight: bold; }
.control { font-style: italic; }
</style>
<pre><code><span class="attribute">#</span><span class="attribute">[</span><span class="attribute">derive</span><span class="attribute">(</span><span class="attribute">Clone</span><span class="attribute">,</span><span class="attribute"> </span><span class="attribute">Debug</span><span class="attribute">)</span><span class="attribute">]</span>
<span class="keyword">struct</span> <span class="type">Foo</span> {
<span class="keyword">pub</span> <span class="field">x</span>: <span class="type builtin">i32</span>,
<span class="keyword">pub</span> <span class="field">y</span>: <span class="type builtin">i32</span>,
<span class="keyword">struct</span> <span class="struct">Foo</span> {
<span class="keyword">pub</span> <span class="field">x</span>: <span class="builtin_type">i32</span>,
<span class="keyword">pub</span> <span class="field">y</span>: <span class="builtin_type">i32</span>,
}
<span class="keyword">fn</span> <span class="function">foo</span>&lt;<span class="type param">T</span>&gt;() -&gt; <span class="type param">T</span> {
<span class="keyword">fn</span> <span class="function">foo</span>&lt;<span class="type_param">T</span>&gt;() -&gt; <span class="type_param">T</span> {
<span class="macro">unimplemented</span><span class="macro">!</span>();
<span class="function">foo</span>::&lt;<span class="type builtin">i32</span>&gt;();
<span class="function">foo</span>::&lt;<span class="builtin_type">i32</span>&gt;();
}
<span class="macro">macro_rules</span><span class="macro">!</span> def_fn {
($($tt:tt)*) =&gt; {$($tt)*}
}
<span class="macro">def_fn</span><span class="macro">!</span>{
<span class="keyword">fn</span> <span class="function">bar</span>() -&gt; <span class="type builtin">u32</span> {
<span class="literal numeric">100</span>
<span class="macro">def_fn</span><span class="macro">!</span> {
<span class="keyword">fn</span> <span class="function">bar</span>() -&gt; <span class="builtin_type">u32</span> {
<span class="numeric_literal">100</span>
}
}
<span class="comment">// comment</span>
<span class="keyword">fn</span> <span class="function">main</span>() {
<span class="macro">println</span><span class="macro">!</span>(<span class="string">"Hello, {}!"</span>, <span class="literal numeric">92</span>);
<span class="macro">println</span><span class="macro">!</span>(<span class="string_literal">"Hello, {}!"</span>, <span class="numeric_literal">92</span>);
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable">vec</span> = Vec::new();
<span class="keyword control">if</span> <span class="keyword">true</span> {
<span class="keyword">let</span> <span class="variable">x</span> = <span class="literal numeric">92</span>;
<span class="variable mutable">vec</span>.push(<span class="type">Foo</span> { <span class="field">x</span>, <span class="field">y</span>: <span class="literal numeric">1</span> });
<span class="keyword">let</span> <span class="variable">x</span> = <span class="numeric_literal">92</span>;
<span class="variable mutable">vec</span>.push(<span class="struct">Foo</span> { <span class="field">x</span>, <span class="field">y</span>: <span class="numeric_literal">1</span> });
}
<span class="keyword unsafe">unsafe</span> { <span class="variable mutable">vec</span>.set_len(<span class="literal numeric">0</span>); }
<span class="keyword unsafe">unsafe</span> { <span class="variable mutable">vec</span>.set_len(<span class="numeric_literal">0</span>); }
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable">x</span> = <span class="literal numeric">42</span>;
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable">x</span> = <span class="numeric_literal">42</span>;
<span class="keyword">let</span> <span class="variable mutable">y</span> = &<span class="keyword">mut</span> <span class="variable mutable">x</span>;
<span class="keyword">let</span> <span class="variable">z</span> = &<span class="variable mutable">y</span>;
<span class="variable mutable">y</span>;
}
<span class="keyword">enum</span> <span class="type">E</span>&lt;<span class="type param">X</span>&gt; {
<span class="constant">V</span>(<span class="type param">X</span>)
<span class="keyword">enum</span> <span class="enum">E</span>&lt;<span class="type_param">X</span>&gt; {
<span class="enum_variant">V</span>(<span class="type_param">X</span>)
}
<span class="keyword">impl</span>&lt;<span class="type param">X</span>&gt; <span class="type">E</span>&lt;<span class="type param">X</span>&gt; {
<span class="keyword">fn</span> <span class="function">new</span>&lt;<span class="type param">T</span>&gt;() -&gt; <span class="type">E</span>&lt;<span class="type param">T</span>&gt; {}
<span class="keyword">impl</span>&lt;<span class="type_param">X</span>&gt; <span class="enum">E</span>&lt;<span class="type_param">X</span>&gt; {
<span class="keyword">fn</span> <span class="function">new</span>&lt;<span class="type_param">T</span>&gt;() -&gt; <span class="enum">E</span>&lt;<span class="type_param">T</span>&gt; {}
}</code></pre>

View file

@ -3,36 +3,38 @@
body { margin: 0; }
pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
.comment { color: #7F9F7F; }
.string { color: #CC9393; }
.struct, .enum { color: #7CB8BB; }
.enum_variant { color: #BDE0F3; }
.string_literal { color: #CC9393; }
.field { color: #94BFF3; }
.function { color: #93E0E3; }
.parameter { color: #94BFF3; }
.text { color: #DCDCCC; }
.type { color: #7CB8BB; }
.type.builtin { color: #8CD0D3; }
.type.param { color: #20999D; }
.builtin_type { color: #8CD0D3; }
.type_param { color: #DFAF8F; }
.attribute { color: #94BFF3; }
.literal { color: #BFEBBF; }
.literal.numeric { color: #6A8759; }
.numeric_literal { color: #BFEBBF; }
.macro { color: #94BFF3; }
.module { color: #AFD8AF; }
.variable { color: #DCDCCC; }
.variable.mut { color: #DCDCCC; text-decoration: underline; }
.mutable { text-decoration: underline; }
.keyword { color: #F0DFAF; }
.keyword.unsafe { color: #DFAF8F; }
.keyword.control { color: #F0DFAF; font-weight: bold; }
.keyword { color: #F0DFAF; font-weight: bold; }
.keyword.unsafe { color: #BC8383; font-weight: bold; }
.control { font-style: italic; }
</style>
<pre><code><span class="keyword">fn</span> <span class="function">main</span>() {
<span class="keyword">let</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string">"hello"</span>;
<span class="keyword">let</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string_literal">"hello"</span>;
<span class="keyword">let</span> <span class="variable" data-binding-hash="2705725358298919760" style="color: hsl(17,51%,74%);">x</span> = <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span>.to_string();
<span class="keyword">let</span> <span class="variable" data-binding-hash="3365759661443752373" style="color: hsl(127,76%,66%);">y</span> = <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span>.to_string();
<span class="keyword">let</span> <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span> = <span class="string">"other color please!"</span>;
<span class="keyword">let</span> <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span> = <span class="string_literal">"other color please!"</span>;
<span class="keyword">let</span> <span class="variable" data-binding-hash="6717528807933952652" style="color: hsl(85,49%,84%);">y</span> = <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span>.to_string();
}
<span class="keyword">fn</span> <span class="function">bar</span>() {
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string">"hello"</span>;
<span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string_literal">"hello"</span>;
}</code></pre>

View file

@ -177,10 +177,11 @@ fn highlight_element(
}
};
match name_kind {
let h = match name_kind {
Some(name_kind) => highlight_name(db, name_kind),
None => highlight_name_by_syntax(name),
}
};
h | HighlightModifier::Definition
}
// Highlight references like the definitions they resolve to
@ -206,12 +207,13 @@ fn highlight_element(
// Simple token-based highlighting
COMMENT => HighlightTag::Comment.into(),
STRING | RAW_STRING | RAW_BYTE_STRING | BYTE_STRING => HighlightTag::LiteralString.into(),
STRING | RAW_STRING | RAW_BYTE_STRING | BYTE_STRING => HighlightTag::StringLiteral.into(),
ATTR => HighlightTag::Attribute.into(),
INT_NUMBER | FLOAT_NUMBER => HighlightTag::LiteralNumeric.into(),
BYTE => HighlightTag::LiteralByte.into(),
CHAR => HighlightTag::LiteralChar.into(),
LIFETIME => HighlightTag::TypeLifetime.into(),
INT_NUMBER | FLOAT_NUMBER => HighlightTag::NumericLiteral.into(),
BYTE => HighlightTag::ByteLiteral.into(),
CHAR => HighlightTag::CharLiteral.into(),
// FIXME: set Declaration for decls
LIFETIME => HighlightTag::Lifetime.into(),
k if k.is_keyword() => {
let h = Highlight::new(HighlightTag::Keyword);
@ -255,20 +257,21 @@ fn highlight_name(db: &RootDatabase, def: NameDefinition) -> Highlight {
NameDefinition::ModuleDef(def) => match def {
hir::ModuleDef::Module(_) => HighlightTag::Module,
hir::ModuleDef::Function(_) => HighlightTag::Function,
hir::ModuleDef::Adt(_) => HighlightTag::Type,
hir::ModuleDef::EnumVariant(_) => HighlightTag::Constant,
hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct,
hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Enum,
hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union,
hir::ModuleDef::EnumVariant(_) => HighlightTag::EnumVariant,
hir::ModuleDef::Const(_) => HighlightTag::Constant,
hir::ModuleDef::Static(_) => HighlightTag::Constant,
hir::ModuleDef::Trait(_) => HighlightTag::Type,
hir::ModuleDef::TypeAlias(_) => HighlightTag::Type,
hir::ModuleDef::BuiltinType(_) => {
return HighlightTag::Type | HighlightModifier::Builtin
}
hir::ModuleDef::Static(_) => HighlightTag::Static,
hir::ModuleDef::Trait(_) => HighlightTag::Trait,
hir::ModuleDef::TypeAlias(_) => HighlightTag::TypeAlias,
hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType,
},
NameDefinition::SelfType(_) => HighlightTag::TypeSelf,
NameDefinition::SelfType(_) => HighlightTag::SelfType,
NameDefinition::TypeParam(_) => HighlightTag::TypeParam,
// FIXME: distinguish between locals and parameters
NameDefinition::Local(local) => {
let mut h = Highlight::new(HighlightTag::Variable);
let mut h = Highlight::new(HighlightTag::Local);
if local.is_mut(db) || local.ty(db).is_mutable_reference() {
h |= HighlightModifier::Mutable;
}
@ -287,7 +290,11 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
};
match parent.kind() {
STRUCT_DEF | ENUM_DEF | TRAIT_DEF | TYPE_ALIAS_DEF => HighlightTag::Type.into(),
STRUCT_DEF => HighlightTag::Struct.into(),
ENUM_DEF => HighlightTag::Enum.into(),
UNION_KW => HighlightTag::Union.into(),
TRAIT_DEF => HighlightTag::Trait.into(),
TYPE_ALIAS_DEF => HighlightTag::TypeAlias.into(),
TYPE_PARAM => HighlightTag::TypeParam.into(),
RECORD_FIELD_DEF => HighlightTag::Field.into(),
_ => default,
@ -312,7 +319,7 @@ fn highlight_injection(
if let Some(range) = literal.open_quote_text_range() {
acc.push(HighlightedRange {
range,
highlight: HighlightTag::LiteralString.into(),
highlight: HighlightTag::StringLiteral.into(),
binding_hash: None,
})
}
@ -327,7 +334,7 @@ fn highlight_injection(
if let Some(range) = literal.close_quote_text_range() {
acc.push(HighlightedRange {
range,
highlight: HighlightTag::LiteralString.into(),
highlight: HighlightTag::StringLiteral.into(),
binding_hash: None,
})
}

View file

@ -80,25 +80,27 @@ const STYLE: &str = "
body { margin: 0; }
pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
.comment { color: #7F9F7F; }
.string { color: #CC9393; }
.struct, .enum { color: #7CB8BB; }
.enum_variant { color: #BDE0F3; }
.string_literal { color: #CC9393; }
.field { color: #94BFF3; }
.function { color: #93E0E3; }
.parameter { color: #94BFF3; }
.text { color: #DCDCCC; }
.type { color: #7CB8BB; }
.type.builtin { color: #8CD0D3; }
.type.param { color: #20999D; }
.builtin_type { color: #8CD0D3; }
.type_param { color: #DFAF8F; }
.attribute { color: #94BFF3; }
.literal { color: #BFEBBF; }
.literal.numeric { color: #6A8759; }
.numeric_literal { color: #BFEBBF; }
.macro { color: #94BFF3; }
.module { color: #AFD8AF; }
.variable { color: #DCDCCC; }
.variable.mut { color: #DCDCCC; text-decoration: underline; }
.mutable { text-decoration: underline; }
.keyword { color: #F0DFAF; }
.keyword.unsafe { color: #DFAF8F; }
.keyword.control { color: #F0DFAF; font-weight: bold; }
.keyword { color: #F0DFAF; font-weight: bold; }
.keyword.unsafe { color: #BC8383; font-weight: bold; }
.control { font-style: italic; }
</style>
";

View file

@ -14,59 +14,71 @@ pub struct HighlightModifiers(u32);
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum HighlightTag {
Attribute,
BuiltinType,
ByteLiteral,
CharLiteral,
Comment,
Constant,
Enum,
EnumVariant,
Field,
Function,
Module,
Constant,
Macro,
Variable,
Type,
TypeSelf,
TypeParam,
TypeLifetime,
LiteralByte,
LiteralNumeric,
LiteralChar,
Comment,
LiteralString,
Attribute,
Keyword,
Lifetime,
Macro,
Module,
NumericLiteral,
SelfType,
Static,
StringLiteral,
Struct,
Trait,
TypeAlias,
TypeParam,
Union,
Local,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(u8)]
pub enum HighlightModifier {
Mutable = 0,
Unsafe,
/// Used with keywords like `if` and `break`.
Control,
Builtin,
Control = 0,
/// `foo` in `fn foo(x: i32)` is a definition, `foo` in `foo(90 + 2)` is
/// not.
Definition,
Mutable,
Unsafe,
}
impl HighlightTag {
fn as_str(self) -> &'static str {
match self {
HighlightTag::Attribute => "attribute",
HighlightTag::BuiltinType => "builtin_type",
HighlightTag::ByteLiteral => "byte_literal",
HighlightTag::CharLiteral => "char_literal",
HighlightTag::Comment => "comment",
HighlightTag::Constant => "constant",
HighlightTag::Enum => "enum",
HighlightTag::EnumVariant => "enum_variant",
HighlightTag::Field => "field",
HighlightTag::Function => "function",
HighlightTag::Module => "module",
HighlightTag::Constant => "constant",
HighlightTag::Macro => "macro",
HighlightTag::Variable => "variable",
HighlightTag::Type => "type",
HighlightTag::TypeSelf => "type.self",
HighlightTag::TypeParam => "type.param",
HighlightTag::TypeLifetime => "type.lifetime",
HighlightTag::LiteralByte => "literal.byte",
HighlightTag::LiteralNumeric => "literal.numeric",
HighlightTag::LiteralChar => "literal.char",
HighlightTag::Comment => "comment",
HighlightTag::LiteralString => "string",
HighlightTag::Attribute => "attribute",
HighlightTag::Keyword => "keyword",
HighlightTag::Lifetime => "lifetime",
HighlightTag::Macro => "macro",
HighlightTag::Module => "module",
HighlightTag::NumericLiteral => "numeric_literal",
HighlightTag::SelfType => "self_type",
HighlightTag::Static => "static",
HighlightTag::StringLiteral => "string_literal",
HighlightTag::Struct => "struct",
HighlightTag::Trait => "trait",
HighlightTag::TypeAlias => "type_alias",
HighlightTag::TypeParam => "type_param",
HighlightTag::Union => "union",
HighlightTag::Local => "variable",
}
}
}
@ -78,19 +90,15 @@ impl fmt::Display for HighlightTag {
}
impl HighlightModifier {
const ALL: &'static [HighlightModifier] = &[
HighlightModifier::Mutable,
HighlightModifier::Unsafe,
HighlightModifier::Control,
HighlightModifier::Builtin,
];
const ALL: &'static [HighlightModifier] =
&[HighlightModifier::Mutable, HighlightModifier::Unsafe, HighlightModifier::Control];
fn as_str(self) -> &'static str {
match self {
HighlightModifier::Control => "control",
HighlightModifier::Definition => "declaration",
HighlightModifier::Mutable => "mutable",
HighlightModifier::Unsafe => "unsafe",
HighlightModifier::Control => "control",
HighlightModifier::Builtin => "builtin",
}
}

View file

@ -26,7 +26,7 @@ macro_rules! def_fn {
($($tt:tt)*) => {$($tt)*}
}
def_fn!{
def_fn! {
fn bar() -> u32 {
100
}

View file

@ -20,11 +20,11 @@ use ra_vfs::LineEndings;
use crate::{
req,
semantic_tokens::{self, ModifierSet, BUILTIN, CONSTANT, CONTROL, MUTABLE, UNSAFE},
semantic_tokens::{self, ModifierSet, CONSTANT, CONTROL, MUTABLE, UNSAFE},
world::WorldSnapshot,
Result,
};
use semantic_tokens::ATTRIBUTE;
use semantic_tokens::{ATTRIBUTE, BUILTIN_TYPE, ENUM_MEMBER, LIFETIME, TYPE_ALIAS, UNION};
pub trait Conv {
type Output;
@ -316,41 +316,43 @@ impl Conv for Highlight {
fn conv(self) -> Self::Output {
let mut mods = ModifierSet::default();
let type_ = match self.tag {
HighlightTag::Struct => SemanticTokenType::STRUCT,
HighlightTag::Enum => SemanticTokenType::ENUM,
HighlightTag::Union => UNION,
HighlightTag::TypeAlias => TYPE_ALIAS,
HighlightTag::Trait => SemanticTokenType::INTERFACE,
HighlightTag::BuiltinType => BUILTIN_TYPE,
HighlightTag::SelfType => SemanticTokenType::TYPE,
HighlightTag::Field => SemanticTokenType::MEMBER,
HighlightTag::Function => SemanticTokenType::FUNCTION,
HighlightTag::Module => SemanticTokenType::NAMESPACE,
HighlightTag::Constant => {
mods |= CONSTANT;
mods |= SemanticTokenModifier::STATIC;
mods |= SemanticTokenModifier::READONLY;
CONSTANT
SemanticTokenType::VARIABLE
}
HighlightTag::Static => {
mods |= SemanticTokenModifier::STATIC;
SemanticTokenType::VARIABLE
}
HighlightTag::EnumVariant => ENUM_MEMBER,
HighlightTag::Macro => SemanticTokenType::MACRO,
HighlightTag::Variable => SemanticTokenType::VARIABLE,
HighlightTag::Type => SemanticTokenType::TYPE,
HighlightTag::TypeSelf => {
mods |= SemanticTokenModifier::REFERENCE;
SemanticTokenType::TYPE
}
HighlightTag::Local => SemanticTokenType::VARIABLE,
HighlightTag::TypeParam => SemanticTokenType::TYPE_PARAMETER,
HighlightTag::TypeLifetime => {
mods |= SemanticTokenModifier::REFERENCE;
SemanticTokenType::LABEL
}
HighlightTag::LiteralByte => SemanticTokenType::NUMBER,
HighlightTag::LiteralNumeric => SemanticTokenType::NUMBER,
HighlightTag::LiteralChar => SemanticTokenType::NUMBER,
HighlightTag::Lifetime => LIFETIME,
HighlightTag::ByteLiteral | HighlightTag::NumericLiteral => SemanticTokenType::NUMBER,
HighlightTag::CharLiteral | HighlightTag::StringLiteral => SemanticTokenType::STRING,
HighlightTag::Comment => SemanticTokenType::COMMENT,
HighlightTag::LiteralString => SemanticTokenType::STRING,
HighlightTag::Attribute => ATTRIBUTE,
HighlightTag::Keyword => SemanticTokenType::KEYWORD,
};
for modifier in self.modifiers.iter() {
let modifier = match modifier {
HighlightModifier::Definition => SemanticTokenModifier::DECLARATION,
HighlightModifier::Control => CONTROL,
HighlightModifier::Mutable => MUTABLE,
HighlightModifier::Unsafe => UNSAFE,
HighlightModifier::Control => CONTROL,
HighlightModifier::Builtin => BUILTIN,
};
mods |= modifier;
}

View file

@ -5,12 +5,16 @@ use std::ops;
use lsp_types::{Range, SemanticToken, SemanticTokenModifier, SemanticTokenType};
pub(crate) const ATTRIBUTE: SemanticTokenType = SemanticTokenType::new("attribute");
pub(crate) const CONSTANT: SemanticTokenType = SemanticTokenType::new("constant");
pub(crate) const BUILTIN_TYPE: SemanticTokenType = SemanticTokenType::new("builtinType");
pub(crate) const ENUM_MEMBER: SemanticTokenType = SemanticTokenType::new("enumMember");
pub(crate) const LIFETIME: SemanticTokenType = SemanticTokenType::new("lifetime");
pub(crate) const TYPE_ALIAS: SemanticTokenType = SemanticTokenType::new("typeAlias");
pub(crate) const UNION: SemanticTokenType = SemanticTokenType::new("union");
pub(crate) const CONSTANT: SemanticTokenModifier = SemanticTokenModifier::new("constant");
pub(crate) const CONTROL: SemanticTokenModifier = SemanticTokenModifier::new("control");
pub(crate) const MUTABLE: SemanticTokenModifier = SemanticTokenModifier::new("mutable");
pub(crate) const UNSAFE: SemanticTokenModifier = SemanticTokenModifier::new("unsafe");
pub(crate) const CONTROL: SemanticTokenModifier = SemanticTokenModifier::new("control");
pub(crate) const BUILTIN: SemanticTokenModifier = SemanticTokenModifier::new("builtin");
pub(crate) const SUPPORTED_TYPES: &[SemanticTokenType] = &[
SemanticTokenType::COMMENT,
@ -34,7 +38,11 @@ pub(crate) const SUPPORTED_TYPES: &[SemanticTokenType] = &[
SemanticTokenType::PARAMETER,
SemanticTokenType::LABEL,
ATTRIBUTE,
CONSTANT,
BUILTIN_TYPE,
ENUM_MEMBER,
LIFETIME,
TYPE_ALIAS,
UNION,
];
pub(crate) const SUPPORTED_MODIFIERS: &[SemanticTokenModifier] = &[
@ -48,10 +56,10 @@ pub(crate) const SUPPORTED_MODIFIERS: &[SemanticTokenModifier] = &[
SemanticTokenModifier::ASYNC,
SemanticTokenModifier::VOLATILE,
SemanticTokenModifier::READONLY,
CONSTANT,
MUTABLE,
UNSAFE,
CONTROL,
BUILTIN,
];
#[derive(Default)]

View file

@ -400,24 +400,42 @@
],
"semanticTokenTypes": [
{
"id": "attribute"
"id": "attribute",
"description": "Style for attributes"
},
{
"id": "constant"
"id": "builtinType",
"description": "Style for builtin types"
},
{
"id": "lifetime",
"description": "Style for lifetimes"
},
{
"id": "typeAlias",
"description": "Style for type aliases"
},
{
"id": "union",
"description": "Style for C-style untagged unions"
}
],
"semanticTokenModifiers": [
{
"id": "mutable"
"id": "constant",
"description": "Style for compile-time constants"
},
{
"id": "unsafe"
"id": "control",
"description": "Style for control flow keywords"
},
{
"id": "control"
"id": "mutable",
"description": "Style for mutable bindings"
},
{
"id": "builtin"
"id": "unsafe",
"description": "Style for unsafe operations"
}
],
"semanticTokenStyleDefaults": [
@ -427,6 +445,50 @@
"meta.attribute"
]
},
{
"selector": "builtinType",
"scope": [
"support.type.primitive"
]
},
{
"selector": "lifetime",
"scope": [
"entity.name.lifetime.rust"
]
},
{
"selector": "typeAlias",
"scope": [
"entity.name.type",
"entity.name.typeAlias"
]
},
{
"selector": "union",
"scope": [
"entity.name.type",
"entity.name.union"
]
},
{
"selector": "keyword.unsafe",
"scope": [
"keyword.other.unsafe"
]
},
{
"selector": "keyword.control",
"scope": [
"keyword.control"
]
},
{
"selector": "variable.constant",
"scope": [
"entity.name.constant"
]
},
{
"selector": "*.mutable",
"light": {
@ -438,24 +500,6 @@
"highContrast": {
"fontStyle": "underline"
}
},
{
"selector": "constant",
"scope": [
"entity.name.constant"
]
},
{
"selector": "keyword.unsafe",
"scope": [
"keyword.other.unsafe"
]
},
{
"selector": "type.builtin",
"scope": [
"support.type.builtin"
]
}
]
}