mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 15:54:15 +00:00
add more tags
This commit is contained in:
parent
4741ae7852
commit
996e18846d
@ -255,15 +255,15 @@ 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::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::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::Trait(_) => HighlightTag::Trait,
|
||||
hir::ModuleDef::TypeAlias(_) => HighlightTag::TypeAlias,
|
||||
hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType,
|
||||
},
|
||||
NameDefinition::SelfType(_) => HighlightTag::TypeSelf,
|
||||
NameDefinition::TypeParam(_) => HighlightTag::TypeParam,
|
||||
@ -287,7 +287,10 @@ 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(),
|
||||
TRAIT_DEF => HighlightTag::Trait.into(),
|
||||
TYPE_ALIAS_DEF => HighlightTag::TypeAlias.into(),
|
||||
TYPE_PARAM => HighlightTag::TypeParam.into(),
|
||||
RECORD_FIELD_DEF => HighlightTag::Field.into(),
|
||||
_ => default,
|
||||
|
@ -14,6 +14,13 @@ pub struct HighlightModifiers(u32);
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub enum HighlightTag {
|
||||
Struct,
|
||||
Enum,
|
||||
Union,
|
||||
Trait,
|
||||
TypeAlias,
|
||||
BuiltinType,
|
||||
|
||||
Field,
|
||||
Function,
|
||||
Module,
|
||||
@ -21,7 +28,6 @@ pub enum HighlightTag {
|
||||
Macro,
|
||||
Variable,
|
||||
|
||||
Type,
|
||||
TypeSelf,
|
||||
TypeParam,
|
||||
TypeLifetime,
|
||||
@ -44,19 +50,24 @@ pub enum HighlightModifier {
|
||||
Unsafe,
|
||||
/// Used with keywords like `if` and `break`.
|
||||
Control,
|
||||
Builtin,
|
||||
}
|
||||
|
||||
impl HighlightTag {
|
||||
fn as_str(self) -> &'static str {
|
||||
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::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",
|
||||
@ -78,19 +89,14 @@ 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::Mutable => "mutable",
|
||||
HighlightModifier::Unsafe => "unsafe",
|
||||
HighlightModifier::Control => "control",
|
||||
HighlightModifier::Builtin => "builtin",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -316,6 +316,12 @@ impl Conv for Highlight {
|
||||
fn conv(self) -> Self::Output {
|
||||
let mut mods = ModifierSet::default();
|
||||
let type_ = match self.tag {
|
||||
HighlightTag::Struct
|
||||
| HighlightTag::Enum
|
||||
| HighlightTag::Union
|
||||
| HighlightTag::TypeAlias
|
||||
| HighlightTag::Trait
|
||||
| HighlightTag::BuiltinType => SemanticTokenType::TYPE,
|
||||
HighlightTag::Field => SemanticTokenType::MEMBER,
|
||||
HighlightTag::Function => SemanticTokenType::FUNCTION,
|
||||
HighlightTag::Module => SemanticTokenType::NAMESPACE,
|
||||
@ -326,7 +332,6 @@ impl Conv for Highlight {
|
||||
}
|
||||
HighlightTag::Macro => SemanticTokenType::MACRO,
|
||||
HighlightTag::Variable => SemanticTokenType::VARIABLE,
|
||||
HighlightTag::Type => SemanticTokenType::TYPE,
|
||||
HighlightTag::TypeSelf => {
|
||||
mods |= SemanticTokenModifier::REFERENCE;
|
||||
SemanticTokenType::TYPE
|
||||
@ -350,7 +355,6 @@ impl Conv for Highlight {
|
||||
HighlightModifier::Mutable => MUTABLE,
|
||||
HighlightModifier::Unsafe => UNSAFE,
|
||||
HighlightModifier::Control => CONTROL,
|
||||
HighlightModifier::Builtin => BUILTIN,
|
||||
};
|
||||
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 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,
|
||||
@ -51,7 +50,6 @@ pub(crate) const SUPPORTED_MODIFIERS: &[SemanticTokenModifier] = &[
|
||||
MUTABLE,
|
||||
UNSAFE,
|
||||
CONTROL,
|
||||
BUILTIN,
|
||||
];
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -398,9 +398,6 @@
|
||||
},
|
||||
{
|
||||
"id": "control"
|
||||
},
|
||||
{
|
||||
"id": "builtin"
|
||||
}
|
||||
],
|
||||
"semanticTokenStyleDefaults": [
|
||||
@ -433,12 +430,6 @@
|
||||
"scope": [
|
||||
"keyword.other.unsafe"
|
||||
]
|
||||
},
|
||||
{
|
||||
"selector": "type.builtin",
|
||||
"scope": [
|
||||
"support.type.builtin"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user