mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
add more tags
This commit is contained in:
parent
4741ae7852
commit
996e18846d
5 changed files with 32 additions and 30 deletions
|
@ -255,15 +255,15 @@ fn highlight_name(db: &RootDatabase, def: NameDefinition) -> Highlight {
|
||||||
NameDefinition::ModuleDef(def) => match def {
|
NameDefinition::ModuleDef(def) => match def {
|
||||||
hir::ModuleDef::Module(_) => HighlightTag::Module,
|
hir::ModuleDef::Module(_) => HighlightTag::Module,
|
||||||
hir::ModuleDef::Function(_) => HighlightTag::Function,
|
hir::ModuleDef::Function(_) => HighlightTag::Function,
|
||||||
hir::ModuleDef::Adt(_) => HighlightTag::Type,
|
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::Constant,
|
hir::ModuleDef::EnumVariant(_) => HighlightTag::Constant,
|
||||||
hir::ModuleDef::Const(_) => HighlightTag::Constant,
|
hir::ModuleDef::Const(_) => HighlightTag::Constant,
|
||||||
hir::ModuleDef::Static(_) => HighlightTag::Constant,
|
hir::ModuleDef::Static(_) => HighlightTag::Constant,
|
||||||
hir::ModuleDef::Trait(_) => HighlightTag::Type,
|
hir::ModuleDef::Trait(_) => HighlightTag::Trait,
|
||||||
hir::ModuleDef::TypeAlias(_) => HighlightTag::Type,
|
hir::ModuleDef::TypeAlias(_) => HighlightTag::TypeAlias,
|
||||||
hir::ModuleDef::BuiltinType(_) => {
|
hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType,
|
||||||
return HighlightTag::Type | HighlightModifier::Builtin
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
NameDefinition::SelfType(_) => HighlightTag::TypeSelf,
|
NameDefinition::SelfType(_) => HighlightTag::TypeSelf,
|
||||||
NameDefinition::TypeParam(_) => HighlightTag::TypeParam,
|
NameDefinition::TypeParam(_) => HighlightTag::TypeParam,
|
||||||
|
@ -287,7 +287,10 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
|
||||||
};
|
};
|
||||||
|
|
||||||
match parent.kind() {
|
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(),
|
||||||
|
TRAIT_DEF => HighlightTag::Trait.into(),
|
||||||
|
TYPE_ALIAS_DEF => HighlightTag::TypeAlias.into(),
|
||||||
TYPE_PARAM => HighlightTag::TypeParam.into(),
|
TYPE_PARAM => HighlightTag::TypeParam.into(),
|
||||||
RECORD_FIELD_DEF => HighlightTag::Field.into(),
|
RECORD_FIELD_DEF => HighlightTag::Field.into(),
|
||||||
_ => default,
|
_ => default,
|
||||||
|
|
|
@ -14,6 +14,13 @@ 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 {
|
||||||
|
Struct,
|
||||||
|
Enum,
|
||||||
|
Union,
|
||||||
|
Trait,
|
||||||
|
TypeAlias,
|
||||||
|
BuiltinType,
|
||||||
|
|
||||||
Field,
|
Field,
|
||||||
Function,
|
Function,
|
||||||
Module,
|
Module,
|
||||||
|
@ -21,7 +28,6 @@ pub enum HighlightTag {
|
||||||
Macro,
|
Macro,
|
||||||
Variable,
|
Variable,
|
||||||
|
|
||||||
Type,
|
|
||||||
TypeSelf,
|
TypeSelf,
|
||||||
TypeParam,
|
TypeParam,
|
||||||
TypeLifetime,
|
TypeLifetime,
|
||||||
|
@ -44,19 +50,24 @@ pub enum HighlightModifier {
|
||||||
Unsafe,
|
Unsafe,
|
||||||
/// Used with keywords like `if` and `break`.
|
/// Used with keywords like `if` and `break`.
|
||||||
Control,
|
Control,
|
||||||
Builtin,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HighlightTag {
|
impl HighlightTag {
|
||||||
fn as_str(self) -> &'static str {
|
fn as_str(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
|
HighlightTag::Struct => "struct",
|
||||||
|
HighlightTag::Enum => "enum",
|
||||||
|
HighlightTag::Union => "union",
|
||||||
|
HighlightTag::Trait => "trait",
|
||||||
|
HighlightTag::TypeAlias => "type_alias",
|
||||||
|
HighlightTag::BuiltinType => "builtin_type",
|
||||||
|
|
||||||
HighlightTag::Field => "field",
|
HighlightTag::Field => "field",
|
||||||
HighlightTag::Function => "function",
|
HighlightTag::Function => "function",
|
||||||
HighlightTag::Module => "module",
|
HighlightTag::Module => "module",
|
||||||
HighlightTag::Constant => "constant",
|
HighlightTag::Constant => "constant",
|
||||||
HighlightTag::Macro => "macro",
|
HighlightTag::Macro => "macro",
|
||||||
HighlightTag::Variable => "variable",
|
HighlightTag::Variable => "variable",
|
||||||
HighlightTag::Type => "type",
|
|
||||||
HighlightTag::TypeSelf => "type.self",
|
HighlightTag::TypeSelf => "type.self",
|
||||||
HighlightTag::TypeParam => "type.param",
|
HighlightTag::TypeParam => "type.param",
|
||||||
HighlightTag::TypeLifetime => "type.lifetime",
|
HighlightTag::TypeLifetime => "type.lifetime",
|
||||||
|
@ -78,19 +89,14 @@ impl fmt::Display for HighlightTag {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HighlightModifier {
|
impl HighlightModifier {
|
||||||
const ALL: &'static [HighlightModifier] = &[
|
const ALL: &'static [HighlightModifier] =
|
||||||
HighlightModifier::Mutable,
|
&[HighlightModifier::Mutable, HighlightModifier::Unsafe, HighlightModifier::Control];
|
||||||
HighlightModifier::Unsafe,
|
|
||||||
HighlightModifier::Control,
|
|
||||||
HighlightModifier::Builtin,
|
|
||||||
];
|
|
||||||
|
|
||||||
fn as_str(self) -> &'static str {
|
fn as_str(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
HighlightModifier::Mutable => "mutable",
|
HighlightModifier::Mutable => "mutable",
|
||||||
HighlightModifier::Unsafe => "unsafe",
|
HighlightModifier::Unsafe => "unsafe",
|
||||||
HighlightModifier::Control => "control",
|
HighlightModifier::Control => "control",
|
||||||
HighlightModifier::Builtin => "builtin",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -316,6 +316,12 @@ impl Conv for Highlight {
|
||||||
fn conv(self) -> Self::Output {
|
fn conv(self) -> Self::Output {
|
||||||
let mut mods = ModifierSet::default();
|
let mut mods = ModifierSet::default();
|
||||||
let type_ = match self.tag {
|
let type_ = match self.tag {
|
||||||
|
HighlightTag::Struct
|
||||||
|
| HighlightTag::Enum
|
||||||
|
| HighlightTag::Union
|
||||||
|
| HighlightTag::TypeAlias
|
||||||
|
| HighlightTag::Trait
|
||||||
|
| HighlightTag::BuiltinType => SemanticTokenType::TYPE,
|
||||||
HighlightTag::Field => SemanticTokenType::MEMBER,
|
HighlightTag::Field => SemanticTokenType::MEMBER,
|
||||||
HighlightTag::Function => SemanticTokenType::FUNCTION,
|
HighlightTag::Function => SemanticTokenType::FUNCTION,
|
||||||
HighlightTag::Module => SemanticTokenType::NAMESPACE,
|
HighlightTag::Module => SemanticTokenType::NAMESPACE,
|
||||||
|
@ -326,7 +332,6 @@ impl Conv for Highlight {
|
||||||
}
|
}
|
||||||
HighlightTag::Macro => SemanticTokenType::MACRO,
|
HighlightTag::Macro => SemanticTokenType::MACRO,
|
||||||
HighlightTag::Variable => SemanticTokenType::VARIABLE,
|
HighlightTag::Variable => SemanticTokenType::VARIABLE,
|
||||||
HighlightTag::Type => SemanticTokenType::TYPE,
|
|
||||||
HighlightTag::TypeSelf => {
|
HighlightTag::TypeSelf => {
|
||||||
mods |= SemanticTokenModifier::REFERENCE;
|
mods |= SemanticTokenModifier::REFERENCE;
|
||||||
SemanticTokenType::TYPE
|
SemanticTokenType::TYPE
|
||||||
|
@ -350,7 +355,6 @@ impl Conv for Highlight {
|
||||||
HighlightModifier::Mutable => MUTABLE,
|
HighlightModifier::Mutable => MUTABLE,
|
||||||
HighlightModifier::Unsafe => UNSAFE,
|
HighlightModifier::Unsafe => UNSAFE,
|
||||||
HighlightModifier::Control => CONTROL,
|
HighlightModifier::Control => CONTROL,
|
||||||
HighlightModifier::Builtin => BUILTIN,
|
|
||||||
};
|
};
|
||||||
mods |= modifier;
|
mods |= modifier;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ pub(crate) const CONSTANT: SemanticTokenType = SemanticTokenType::new("constant"
|
||||||
pub(crate) const MUTABLE: SemanticTokenModifier = SemanticTokenModifier::new("mutable");
|
pub(crate) const MUTABLE: SemanticTokenModifier = SemanticTokenModifier::new("mutable");
|
||||||
pub(crate) const UNSAFE: SemanticTokenModifier = SemanticTokenModifier::new("unsafe");
|
pub(crate) const UNSAFE: SemanticTokenModifier = SemanticTokenModifier::new("unsafe");
|
||||||
pub(crate) const CONTROL: SemanticTokenModifier = SemanticTokenModifier::new("control");
|
pub(crate) const CONTROL: SemanticTokenModifier = SemanticTokenModifier::new("control");
|
||||||
pub(crate) const BUILTIN: SemanticTokenModifier = SemanticTokenModifier::new("builtin");
|
|
||||||
|
|
||||||
pub(crate) const SUPPORTED_TYPES: &[SemanticTokenType] = &[
|
pub(crate) const SUPPORTED_TYPES: &[SemanticTokenType] = &[
|
||||||
SemanticTokenType::COMMENT,
|
SemanticTokenType::COMMENT,
|
||||||
|
@ -51,7 +50,6 @@ pub(crate) const SUPPORTED_MODIFIERS: &[SemanticTokenModifier] = &[
|
||||||
MUTABLE,
|
MUTABLE,
|
||||||
UNSAFE,
|
UNSAFE,
|
||||||
CONTROL,
|
CONTROL,
|
||||||
BUILTIN,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
|
@ -398,9 +398,6 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "control"
|
"id": "control"
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "builtin"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"semanticTokenStyleDefaults": [
|
"semanticTokenStyleDefaults": [
|
||||||
|
@ -433,12 +430,6 @@
|
||||||
"scope": [
|
"scope": [
|
||||||
"keyword.other.unsafe"
|
"keyword.other.unsafe"
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"selector": "type.builtin",
|
|
||||||
"scope": [
|
|
||||||
"support.type.builtin"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue