mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-09 14:25:24 +00:00
Merge #4556
4556: More highlighting improvements r=matthewjasper a=matthewjasper * Separate `true` and `false` from keywords (this matches the Textmate grammar). * Handle more cases in `highlight_name_by_syntax`. Co-authored-by: Matthew Jasper <mjjasper1@gmail.com>
This commit is contained in:
commit
d959c913ea
@ -17,6 +17,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||||||
.type_param { color: #DFAF8F; }
|
.type_param { color: #DFAF8F; }
|
||||||
.attribute { color: #94BFF3; }
|
.attribute { color: #94BFF3; }
|
||||||
.numeric_literal { color: #BFEBBF; }
|
.numeric_literal { color: #BFEBBF; }
|
||||||
|
.bool_literal { color: #BFE6EB; }
|
||||||
.macro { color: #94BFF3; }
|
.macro { color: #94BFF3; }
|
||||||
.module { color: #AFD8AF; }
|
.module { color: #AFD8AF; }
|
||||||
.variable { color: #DCDCCC; }
|
.variable { color: #DCDCCC; }
|
||||||
|
@ -17,6 +17,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||||||
.type_param { color: #DFAF8F; }
|
.type_param { color: #DFAF8F; }
|
||||||
.attribute { color: #94BFF3; }
|
.attribute { color: #94BFF3; }
|
||||||
.numeric_literal { color: #BFEBBF; }
|
.numeric_literal { color: #BFEBBF; }
|
||||||
|
.bool_literal { color: #BFE6EB; }
|
||||||
.macro { color: #94BFF3; }
|
.macro { color: #94BFF3; }
|
||||||
.module { color: #AFD8AF; }
|
.module { color: #AFD8AF; }
|
||||||
.variable { color: #DCDCCC; }
|
.variable { color: #DCDCCC; }
|
||||||
|
@ -17,6 +17,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||||||
.type_param { color: #DFAF8F; }
|
.type_param { color: #DFAF8F; }
|
||||||
.attribute { color: #94BFF3; }
|
.attribute { color: #94BFF3; }
|
||||||
.numeric_literal { color: #BFEBBF; }
|
.numeric_literal { color: #BFEBBF; }
|
||||||
|
.bool_literal { color: #BFE6EB; }
|
||||||
.macro { color: #94BFF3; }
|
.macro { color: #94BFF3; }
|
||||||
.module { color: #AFD8AF; }
|
.module { color: #AFD8AF; }
|
||||||
.variable { color: #DCDCCC; }
|
.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="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">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="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> });
|
<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> });
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||||||
.type_param { color: #DFAF8F; }
|
.type_param { color: #DFAF8F; }
|
||||||
.attribute { color: #94BFF3; }
|
.attribute { color: #94BFF3; }
|
||||||
.numeric_literal { color: #BFEBBF; }
|
.numeric_literal { color: #BFEBBF; }
|
||||||
|
.bool_literal { color: #BFE6EB; }
|
||||||
.macro { color: #94BFF3; }
|
.macro { color: #94BFF3; }
|
||||||
.module { color: #AFD8AF; }
|
.module { color: #AFD8AF; }
|
||||||
.variable { color: #DCDCCC; }
|
.variable { color: #DCDCCC; }
|
||||||
|
@ -413,6 +413,7 @@ fn highlight_element(
|
|||||||
| T![in] => h | HighlightModifier::ControlFlow,
|
| T![in] => h | HighlightModifier::ControlFlow,
|
||||||
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(),
|
||||||
_ => h,
|
_ => h,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -480,23 +481,31 @@ fn highlight_name(db: &RootDatabase, def: Definition) -> Highlight {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
|
fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
|
||||||
let default = HighlightTag::Function.into();
|
let default = HighlightTag::UnresolvedReference;
|
||||||
|
|
||||||
let parent = match name.syntax().parent() {
|
let parent = match name.syntax().parent() {
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
_ => return default,
|
_ => return default.into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
match parent.kind() {
|
let tag = match parent.kind() {
|
||||||
STRUCT_DEF => HighlightTag::Struct.into(),
|
STRUCT_DEF => HighlightTag::Struct,
|
||||||
ENUM_DEF => HighlightTag::Enum.into(),
|
ENUM_DEF => HighlightTag::Enum,
|
||||||
UNION_DEF => HighlightTag::Union.into(),
|
UNION_DEF => HighlightTag::Union,
|
||||||
TRAIT_DEF => HighlightTag::Trait.into(),
|
TRAIT_DEF => HighlightTag::Trait,
|
||||||
TYPE_ALIAS_DEF => HighlightTag::TypeAlias.into(),
|
TYPE_ALIAS_DEF => HighlightTag::TypeAlias,
|
||||||
TYPE_PARAM => HighlightTag::TypeParam.into(),
|
TYPE_PARAM => HighlightTag::TypeParam,
|
||||||
RECORD_FIELD_DEF => HighlightTag::Field.into(),
|
RECORD_FIELD_DEF => HighlightTag::Field,
|
||||||
|
MODULE => HighlightTag::Module,
|
||||||
|
FN_DEF => HighlightTag::Function,
|
||||||
|
CONST_DEF => HighlightTag::Constant,
|
||||||
|
STATIC_DEF => HighlightTag::Static,
|
||||||
|
ENUM_VARIANT => HighlightTag::EnumVariant,
|
||||||
|
BIND_PAT => HighlightTag::Local,
|
||||||
_ => default,
|
_ => default,
|
||||||
}
|
};
|
||||||
|
|
||||||
|
tag.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn highlight_injection(
|
fn highlight_injection(
|
||||||
|
@ -76,6 +76,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
|||||||
.type_param { color: #DFAF8F; }
|
.type_param { color: #DFAF8F; }
|
||||||
.attribute { color: #94BFF3; }
|
.attribute { color: #94BFF3; }
|
||||||
.numeric_literal { color: #BFEBBF; }
|
.numeric_literal { color: #BFEBBF; }
|
||||||
|
.bool_literal { color: #BFE6EB; }
|
||||||
.macro { color: #94BFF3; }
|
.macro { color: #94BFF3; }
|
||||||
.module { color: #AFD8AF; }
|
.module { color: #AFD8AF; }
|
||||||
.variable { color: #DCDCCC; }
|
.variable { color: #DCDCCC; }
|
||||||
|
@ -15,6 +15,7 @@ pub struct HighlightModifiers(u32);
|
|||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
pub enum HighlightTag {
|
pub enum HighlightTag {
|
||||||
Attribute,
|
Attribute,
|
||||||
|
BoolLiteral,
|
||||||
BuiltinType,
|
BuiltinType,
|
||||||
ByteLiteral,
|
ByteLiteral,
|
||||||
CharLiteral,
|
CharLiteral,
|
||||||
@ -60,6 +61,7 @@ impl HighlightTag {
|
|||||||
fn as_str(self) -> &'static str {
|
fn as_str(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
HighlightTag::Attribute => "attribute",
|
HighlightTag::Attribute => "attribute",
|
||||||
|
HighlightTag::BoolLiteral => "bool_literal",
|
||||||
HighlightTag::BuiltinType => "builtin_type",
|
HighlightTag::BuiltinType => "builtin_type",
|
||||||
HighlightTag::ByteLiteral => "byte_literal",
|
HighlightTag::ByteLiteral => "byte_literal",
|
||||||
HighlightTag::CharLiteral => "char_literal",
|
HighlightTag::CharLiteral => "char_literal",
|
||||||
|
@ -36,6 +36,7 @@ macro_rules! define_semantic_token_types {
|
|||||||
|
|
||||||
define_semantic_token_types![
|
define_semantic_token_types![
|
||||||
(ATTRIBUTE, "attribute"),
|
(ATTRIBUTE, "attribute"),
|
||||||
|
(BOOLEAN, "boolean"),
|
||||||
(BUILTIN_TYPE, "builtinType"),
|
(BUILTIN_TYPE, "builtinType"),
|
||||||
(ENUM_MEMBER, "enumMember"),
|
(ENUM_MEMBER, "enumMember"),
|
||||||
(LIFETIME, "lifetime"),
|
(LIFETIME, "lifetime"),
|
||||||
|
@ -295,6 +295,7 @@ fn semantic_token_type_and_modifiers(
|
|||||||
HighlightTag::ByteLiteral | HighlightTag::NumericLiteral => {
|
HighlightTag::ByteLiteral | HighlightTag::NumericLiteral => {
|
||||||
lsp_types::SemanticTokenType::NUMBER
|
lsp_types::SemanticTokenType::NUMBER
|
||||||
}
|
}
|
||||||
|
HighlightTag::BoolLiteral => semantic_tokens::BOOLEAN,
|
||||||
HighlightTag::CharLiteral | HighlightTag::StringLiteral => {
|
HighlightTag::CharLiteral | HighlightTag::StringLiteral => {
|
||||||
lsp_types::SemanticTokenType::STRING
|
lsp_types::SemanticTokenType::STRING
|
||||||
}
|
}
|
||||||
|
@ -644,6 +644,9 @@
|
|||||||
"function.attribute": [
|
"function.attribute": [
|
||||||
"entity.name.function.attribute.rust"
|
"entity.name.function.attribute.rust"
|
||||||
],
|
],
|
||||||
|
"boolean": [
|
||||||
|
"constant.language.boolean.rust"
|
||||||
|
],
|
||||||
"builtinType": [
|
"builtinType": [
|
||||||
"support.type.primitive.rust"
|
"support.type.primitive.rust"
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user