From c45221907adde640208a9e52636f4845d4654994 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 18 Dec 2020 23:00:43 +0300 Subject: Deduplicate highlight tags and symbol kinds Curiously, LSP uses different enums for those, and unsurprising and annoyingly, there are things which exist in one but not in the other. Let's not repeat the mistake and unify the two things --- crates/ide/src/syntax_highlighting/format.rs | 6 ++- crates/ide/src/syntax_highlighting/tags.rs | 76 ++++++++++++---------------- 2 files changed, 37 insertions(+), 45 deletions(-) (limited to 'crates/ide/src/syntax_highlighting') diff --git a/crates/ide/src/syntax_highlighting/format.rs b/crates/ide/src/syntax_highlighting/format.rs index 42f27df5d..26416022b 100644 --- a/crates/ide/src/syntax_highlighting/format.rs +++ b/crates/ide/src/syntax_highlighting/format.rs @@ -4,7 +4,9 @@ use syntax::{ AstNode, AstToken, SyntaxElement, SyntaxKind, SyntaxNode, TextRange, }; -use crate::{syntax_highlighting::HighlightedRangeStack, HighlightTag, HighlightedRange}; +use crate::{ + syntax_highlighting::HighlightedRangeStack, HighlightTag, HighlightedRange, SymbolKind, +}; #[derive(Default)] pub(super) struct FormatStringHighlighter { @@ -71,6 +73,6 @@ fn highlight_format_specifier(kind: FormatSpecifier) -> Option { | FormatSpecifier::Asterisk | FormatSpecifier::QuestionMark => HighlightTag::FormatSpecifier, FormatSpecifier::Integer | FormatSpecifier::Zero => HighlightTag::NumericLiteral, - FormatSpecifier::Identifier => HighlightTag::Local, + FormatSpecifier::Identifier => HighlightTag::Symbol(SymbolKind::Local), }) } diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index ffd9588b8..e0117a6b2 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs @@ -3,6 +3,8 @@ use std::{fmt, ops}; +use crate::SymbolKind; + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct Highlight { pub tag: HighlightTag, @@ -14,40 +16,26 @@ pub struct HighlightModifiers(u32); #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub enum HighlightTag { - Attribute, + Symbol(SymbolKind), + BoolLiteral, BuiltinType, ByteLiteral, CharLiteral, + NumericLiteral, + StringLiteral, + Attribute, Comment, - Constant, - Enum, - EnumVariant, EscapeSequence, - Field, - Function, - Generic, + FormatSpecifier, Keyword, - Lifetime, - Macro, - Method, - Module, - NumericLiteral, Punctuation, - SelfKeyword, - SelfType, - Static, - StringLiteral, - Struct, - Trait, - TypeAlias, - TypeParam, - Union, - ValueParam, - Local, - UnresolvedReference, - FormatSpecifier, Operator, + UnresolvedReference, + + // FIXME: this two are random and don't fit with the others + Method, + Generic, } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] @@ -73,39 +61,41 @@ pub enum HighlightModifier { impl HighlightTag { fn as_str(self) -> &'static str { match self { + HighlightTag::Symbol(symbol) => match symbol { + SymbolKind::Const => "constant", + SymbolKind::Static => "static", + SymbolKind::Enum => "enum", + SymbolKind::Variant => "enum_variant", + SymbolKind::Struct => "struct", + SymbolKind::Union => "union", + SymbolKind::Field => "field", + SymbolKind::Module => "module", + SymbolKind::Trait => "trait", + SymbolKind::Function => "function", + SymbolKind::TypeAlias => "type_alias", + SymbolKind::TypeParam => "type_param", + SymbolKind::LifetimeParam => "lifetime", + SymbolKind::Macro => "macro", + SymbolKind::Local => "variable", + SymbolKind::ValueParam => "value_param", + SymbolKind::SelfParam => "self_keyword", + SymbolKind::Impl => "self_type", + }, HighlightTag::Attribute => "attribute", HighlightTag::BoolLiteral => "bool_literal", HighlightTag::BuiltinType => "builtin_type", HighlightTag::ByteLiteral => "byte_literal", HighlightTag::CharLiteral => "char_literal", HighlightTag::Comment => "comment", - HighlightTag::Constant => "constant", - HighlightTag::Enum => "enum", - HighlightTag::EnumVariant => "enum_variant", HighlightTag::EscapeSequence => "escape_sequence", - HighlightTag::Field => "field", HighlightTag::FormatSpecifier => "format_specifier", - HighlightTag::Function => "function", HighlightTag::Generic => "generic", HighlightTag::Keyword => "keyword", - HighlightTag::Lifetime => "lifetime", HighlightTag::Punctuation => "punctuation", - HighlightTag::Macro => "macro", HighlightTag::Method => "method", - HighlightTag::Module => "module", HighlightTag::NumericLiteral => "numeric_literal", HighlightTag::Operator => "operator", - HighlightTag::SelfKeyword => "self_keyword", - HighlightTag::SelfType => "self_type", - HighlightTag::Static => "static", HighlightTag::StringLiteral => "string_literal", - HighlightTag::Struct => "struct", - HighlightTag::Trait => "trait", - HighlightTag::TypeAlias => "type_alias", - HighlightTag::TypeParam => "type_param", - HighlightTag::Union => "union", - HighlightTag::ValueParam => "value_param", - HighlightTag::Local => "variable", HighlightTag::UnresolvedReference => "unresolved_reference", } } -- cgit v1.2.3