Highlight true and false as literals

This commit is contained in:
Matthew Jasper 2020-05-21 17:40:52 +01:00
parent 7e862626cc
commit e2d36cb692
10 changed files with 14 additions and 1 deletions

View file

@ -17,6 +17,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.type_param { color: #DFAF8F; }
.attribute { color: #94BFF3; }
.numeric_literal { color: #BFEBBF; }
.bool_literal { color: #BFE6EB; }
.macro { color: #94BFF3; }
.module { color: #AFD8AF; }
.variable { color: #DCDCCC; }

View file

@ -17,6 +17,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.type_param { color: #DFAF8F; }
.attribute { color: #94BFF3; }
.numeric_literal { color: #BFEBBF; }
.bool_literal { color: #BFE6EB; }
.macro { color: #94BFF3; }
.module { color: #AFD8AF; }
.variable { color: #DCDCCC; }

View file

@ -17,6 +17,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.type_param { color: #DFAF8F; }
.attribute { color: #94BFF3; }
.numeric_literal { color: #BFEBBF; }
.bool_literal { color: #BFE6EB; }
.macro { color: #94BFF3; }
.module { color: #AFD8AF; }
.variable { color: #DCDCCC; }
@ -64,7 +65,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
<span class="macro">println!</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 declaration mutable">vec</span> = <span class="unresolved_reference">Vec</span>::<span class="unresolved_reference">new</span>();
<span class="keyword control">if</span> <span class="keyword">true</span> {
<span class="keyword control">if</span> <span class="bool_literal">true</span> {
<span class="keyword">let</span> <span class="variable declaration">x</span> = <span class="numeric_literal">92</span>;
<span class="variable mutable">vec</span>.<span class="unresolved_reference">push</span>(<span class="struct">Foo</span> { <span class="field">x</span>, <span class="field">y</span>: <span class="numeric_literal">1</span> });
}

View file

@ -17,6 +17,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.type_param { color: #DFAF8F; }
.attribute { color: #94BFF3; }
.numeric_literal { color: #BFEBBF; }
.bool_literal { color: #BFE6EB; }
.macro { color: #94BFF3; }
.module { color: #AFD8AF; }
.variable { color: #DCDCCC; }

View file

@ -413,6 +413,7 @@ fn highlight_element(
| T![in] => h | HighlightModifier::ControlFlow,
T![for] if !is_child_of_impl(element) => h | HighlightModifier::ControlFlow,
T![unsafe] => h | HighlightModifier::Unsafe,
T![true] | T![false] => HighlightTag::BoolLiteral.into(),
_ => h,
}
}

View file

@ -76,6 +76,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
.type_param { color: #DFAF8F; }
.attribute { color: #94BFF3; }
.numeric_literal { color: #BFEBBF; }
.bool_literal { color: #BFE6EB; }
.macro { color: #94BFF3; }
.module { color: #AFD8AF; }
.variable { color: #DCDCCC; }

View file

@ -15,6 +15,7 @@ pub struct HighlightModifiers(u32);
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum HighlightTag {
Attribute,
BoolLiteral,
BuiltinType,
ByteLiteral,
CharLiteral,
@ -60,6 +61,7 @@ impl HighlightTag {
fn as_str(self) -> &'static str {
match self {
HighlightTag::Attribute => "attribute",
HighlightTag::BoolLiteral => "bool_literal",
HighlightTag::BuiltinType => "builtin_type",
HighlightTag::ByteLiteral => "byte_literal",
HighlightTag::CharLiteral => "char_literal",

View file

@ -36,6 +36,7 @@ macro_rules! define_semantic_token_types {
define_semantic_token_types![
(ATTRIBUTE, "attribute"),
(BOOLEAN, "boolean"),
(BUILTIN_TYPE, "builtinType"),
(ENUM_MEMBER, "enumMember"),
(LIFETIME, "lifetime"),

View file

@ -295,6 +295,7 @@ fn semantic_token_type_and_modifiers(
HighlightTag::ByteLiteral | HighlightTag::NumericLiteral => {
lsp_types::SemanticTokenType::NUMBER
}
HighlightTag::BoolLiteral => semantic_tokens::BOOLEAN,
HighlightTag::CharLiteral | HighlightTag::StringLiteral => {
lsp_types::SemanticTokenType::STRING
}

View file

@ -644,6 +644,9 @@
"function.attribute": [
"entity.name.function.attribute.rust"
],
"boolean": [
"constant.language.boolean.rust"
],
"builtinType": [
"support.type.primitive.rust"
],