From 996e18846dab8e5c4a2846641289f85fe99eb480 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 27 Feb 2020 19:00:10 +0100 Subject: [PATCH] add more tags --- crates/ra_ide/src/syntax_highlighting.rs | 17 +++++++----- crates/ra_ide/src/syntax_highlighting/tags.rs | 26 ++++++++++++------- crates/rust-analyzer/src/conv.rs | 8 ++++-- crates/rust-analyzer/src/semantic_tokens.rs | 2 -- editors/code/package.json | 9 ------- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index d7bca11933..ae2163f9f7 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -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, diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs index 383c74c986..df2fc3c48f 100644 --- a/crates/ra_ide/src/syntax_highlighting/tags.rs +++ b/crates/ra_ide/src/syntax_highlighting/tags.rs @@ -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", } } diff --git a/crates/rust-analyzer/src/conv.rs b/crates/rust-analyzer/src/conv.rs index b012f5dd5e..e4255e24ad 100644 --- a/crates/rust-analyzer/src/conv.rs +++ b/crates/rust-analyzer/src/conv.rs @@ -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; } diff --git a/crates/rust-analyzer/src/semantic_tokens.rs b/crates/rust-analyzer/src/semantic_tokens.rs index d8362409dc..3069f30547 100644 --- a/crates/rust-analyzer/src/semantic_tokens.rs +++ b/crates/rust-analyzer/src/semantic_tokens.rs @@ -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)] diff --git a/editors/code/package.json b/editors/code/package.json index 5effa3e172..fd29710ba0 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -398,9 +398,6 @@ }, { "id": "control" - }, - { - "id": "builtin" } ], "semanticTokenStyleDefaults": [ @@ -433,12 +430,6 @@ "scope": [ "keyword.other.unsafe" ] - }, - { - "selector": "type.builtin", - "scope": [ - "support.type.builtin" - ] } ] }