aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/syntax_highlighting
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-12-18 20:05:20 +0000
committerGitHub <[email protected]>2020-12-18 20:05:20 +0000
commitc7b7c37ea5f25806d8c523e309b7ee9be27f2cde (patch)
tree7ea6a6b3c6796223f9acffa7b549a95b7661cef3 /crates/ide/src/syntax_highlighting
parent38b108c20e82d003938f34cfebbfd4cb964a8de8 (diff)
parentc45221907adde640208a9e52636f4845d4654994 (diff)
Merge #6937
6937: Deduplicate highlight tags and symbol kinds r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ide/src/syntax_highlighting')
-rw-r--r--crates/ide/src/syntax_highlighting/format.rs6
-rw-r--r--crates/ide/src/syntax_highlighting/tags.rs76
2 files changed, 37 insertions, 45 deletions
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::{
4 AstNode, AstToken, SyntaxElement, SyntaxKind, SyntaxNode, TextRange, 4 AstNode, AstToken, SyntaxElement, SyntaxKind, SyntaxNode, TextRange,
5}; 5};
6 6
7use crate::{syntax_highlighting::HighlightedRangeStack, HighlightTag, HighlightedRange}; 7use crate::{
8 syntax_highlighting::HighlightedRangeStack, HighlightTag, HighlightedRange, SymbolKind,
9};
8 10
9#[derive(Default)] 11#[derive(Default)]
10pub(super) struct FormatStringHighlighter { 12pub(super) struct FormatStringHighlighter {
@@ -71,6 +73,6 @@ fn highlight_format_specifier(kind: FormatSpecifier) -> Option<HighlightTag> {
71 | FormatSpecifier::Asterisk 73 | FormatSpecifier::Asterisk
72 | FormatSpecifier::QuestionMark => HighlightTag::FormatSpecifier, 74 | FormatSpecifier::QuestionMark => HighlightTag::FormatSpecifier,
73 FormatSpecifier::Integer | FormatSpecifier::Zero => HighlightTag::NumericLiteral, 75 FormatSpecifier::Integer | FormatSpecifier::Zero => HighlightTag::NumericLiteral,
74 FormatSpecifier::Identifier => HighlightTag::Local, 76 FormatSpecifier::Identifier => HighlightTag::Symbol(SymbolKind::Local),
75 }) 77 })
76} 78}
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 @@
3 3
4use std::{fmt, ops}; 4use std::{fmt, ops};
5 5
6use crate::SymbolKind;
7
6#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 8#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
7pub struct Highlight { 9pub struct Highlight {
8 pub tag: HighlightTag, 10 pub tag: HighlightTag,
@@ -14,40 +16,26 @@ pub struct HighlightModifiers(u32);
14 16
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 17#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub enum HighlightTag { 18pub enum HighlightTag {
17 Attribute, 19 Symbol(SymbolKind),
20
18 BoolLiteral, 21 BoolLiteral,
19 BuiltinType, 22 BuiltinType,
20 ByteLiteral, 23 ByteLiteral,
21 CharLiteral, 24 CharLiteral,
25 NumericLiteral,
26 StringLiteral,
27 Attribute,
22 Comment, 28 Comment,
23 Constant,
24 Enum,
25 EnumVariant,
26 EscapeSequence, 29 EscapeSequence,
27 Field, 30 FormatSpecifier,
28 Function,
29 Generic,
30 Keyword, 31 Keyword,
31 Lifetime,
32 Macro,
33 Method,
34 Module,
35 NumericLiteral,
36 Punctuation, 32 Punctuation,
37 SelfKeyword,
38 SelfType,
39 Static,
40 StringLiteral,
41 Struct,
42 Trait,
43 TypeAlias,
44 TypeParam,
45 Union,
46 ValueParam,
47 Local,
48 UnresolvedReference,
49 FormatSpecifier,
50 Operator, 33 Operator,
34 UnresolvedReference,
35
36 // FIXME: this two are random and don't fit with the others
37 Method,
38 Generic,
51} 39}
52 40
53#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 41#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
@@ -73,39 +61,41 @@ pub enum HighlightModifier {
73impl HighlightTag { 61impl HighlightTag {
74 fn as_str(self) -> &'static str { 62 fn as_str(self) -> &'static str {
75 match self { 63 match self {
64 HighlightTag::Symbol(symbol) => match symbol {
65 SymbolKind::Const => "constant",
66 SymbolKind::Static => "static",
67 SymbolKind::Enum => "enum",
68 SymbolKind::Variant => "enum_variant",
69 SymbolKind::Struct => "struct",
70 SymbolKind::Union => "union",
71 SymbolKind::Field => "field",
72 SymbolKind::Module => "module",
73 SymbolKind::Trait => "trait",
74 SymbolKind::Function => "function",
75 SymbolKind::TypeAlias => "type_alias",
76 SymbolKind::TypeParam => "type_param",
77 SymbolKind::LifetimeParam => "lifetime",
78 SymbolKind::Macro => "macro",
79 SymbolKind::Local => "variable",
80 SymbolKind::ValueParam => "value_param",
81 SymbolKind::SelfParam => "self_keyword",
82 SymbolKind::Impl => "self_type",
83 },
76 HighlightTag::Attribute => "attribute", 84 HighlightTag::Attribute => "attribute",
77 HighlightTag::BoolLiteral => "bool_literal", 85 HighlightTag::BoolLiteral => "bool_literal",
78 HighlightTag::BuiltinType => "builtin_type", 86 HighlightTag::BuiltinType => "builtin_type",
79 HighlightTag::ByteLiteral => "byte_literal", 87 HighlightTag::ByteLiteral => "byte_literal",
80 HighlightTag::CharLiteral => "char_literal", 88 HighlightTag::CharLiteral => "char_literal",
81 HighlightTag::Comment => "comment", 89 HighlightTag::Comment => "comment",
82 HighlightTag::Constant => "constant",
83 HighlightTag::Enum => "enum",
84 HighlightTag::EnumVariant => "enum_variant",
85 HighlightTag::EscapeSequence => "escape_sequence", 90 HighlightTag::EscapeSequence => "escape_sequence",
86 HighlightTag::Field => "field",
87 HighlightTag::FormatSpecifier => "format_specifier", 91 HighlightTag::FormatSpecifier => "format_specifier",
88 HighlightTag::Function => "function",
89 HighlightTag::Generic => "generic", 92 HighlightTag::Generic => "generic",
90 HighlightTag::Keyword => "keyword", 93 HighlightTag::Keyword => "keyword",
91 HighlightTag::Lifetime => "lifetime",
92 HighlightTag::Punctuation => "punctuation", 94 HighlightTag::Punctuation => "punctuation",
93 HighlightTag::Macro => "macro",
94 HighlightTag::Method => "method", 95 HighlightTag::Method => "method",
95 HighlightTag::Module => "module",
96 HighlightTag::NumericLiteral => "numeric_literal", 96 HighlightTag::NumericLiteral => "numeric_literal",
97 HighlightTag::Operator => "operator", 97 HighlightTag::Operator => "operator",
98 HighlightTag::SelfKeyword => "self_keyword",
99 HighlightTag::SelfType => "self_type",
100 HighlightTag::Static => "static",
101 HighlightTag::StringLiteral => "string_literal", 98 HighlightTag::StringLiteral => "string_literal",
102 HighlightTag::Struct => "struct",
103 HighlightTag::Trait => "trait",
104 HighlightTag::TypeAlias => "type_alias",
105 HighlightTag::TypeParam => "type_param",
106 HighlightTag::Union => "union",
107 HighlightTag::ValueParam => "value_param",
108 HighlightTag::Local => "variable",
109 HighlightTag::UnresolvedReference => "unresolved_reference", 99 HighlightTag::UnresolvedReference => "unresolved_reference",
110 } 100 }
111 } 101 }