aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-28 11:06:54 +0000
committerAleksey Kladov <[email protected]>2020-02-28 11:13:37 +0000
commit701cf436063590c710cd7783032b5e7c3c41af22 (patch)
treeff841ad4f60074f76c6d1118799ffc5986d6b7bc /crates/ra_ide/src
parent996e18846dab8e5c4a2846641289f85fe99eb480 (diff)
Cleanup highlighting tags
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs30
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tags.rs92
2 files changed, 64 insertions, 58 deletions
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index ae2163f9f..30ca9d8b0 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -177,10 +177,11 @@ fn highlight_element(
177 } 177 }
178 }; 178 };
179 179
180 match name_kind { 180 let h = match name_kind {
181 Some(name_kind) => highlight_name(db, name_kind), 181 Some(name_kind) => highlight_name(db, name_kind),
182 None => highlight_name_by_syntax(name), 182 None => highlight_name_by_syntax(name),
183 } 183 };
184 h | HighlightModifier::Definition
184 } 185 }
185 186
186 // Highlight references like the definitions they resolve to 187 // Highlight references like the definitions they resolve to
@@ -206,12 +207,13 @@ fn highlight_element(
206 207
207 // Simple token-based highlighting 208 // Simple token-based highlighting
208 COMMENT => HighlightTag::Comment.into(), 209 COMMENT => HighlightTag::Comment.into(),
209 STRING | RAW_STRING | RAW_BYTE_STRING | BYTE_STRING => HighlightTag::LiteralString.into(), 210 STRING | RAW_STRING | RAW_BYTE_STRING | BYTE_STRING => HighlightTag::StringLiteral.into(),
210 ATTR => HighlightTag::Attribute.into(), 211 ATTR => HighlightTag::Attribute.into(),
211 INT_NUMBER | FLOAT_NUMBER => HighlightTag::LiteralNumeric.into(), 212 INT_NUMBER | FLOAT_NUMBER => HighlightTag::NumericLiteral.into(),
212 BYTE => HighlightTag::LiteralByte.into(), 213 BYTE => HighlightTag::ByteLiteral.into(),
213 CHAR => HighlightTag::LiteralChar.into(), 214 CHAR => HighlightTag::CharLiteral.into(),
214 LIFETIME => HighlightTag::TypeLifetime.into(), 215 // FIXME: set Declaration for decls
216 LIFETIME => HighlightTag::Lifetime.into(),
215 217
216 k if k.is_keyword() => { 218 k if k.is_keyword() => {
217 let h = Highlight::new(HighlightTag::Keyword); 219 let h = Highlight::new(HighlightTag::Keyword);
@@ -258,17 +260,18 @@ fn highlight_name(db: &RootDatabase, def: NameDefinition) -> Highlight {
258 hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct, 260 hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct,
259 hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Enum, 261 hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Enum,
260 hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union, 262 hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union,
261 hir::ModuleDef::EnumVariant(_) => HighlightTag::Constant, 263 hir::ModuleDef::EnumVariant(_) => HighlightTag::EnumVariant,
262 hir::ModuleDef::Const(_) => HighlightTag::Constant, 264 hir::ModuleDef::Const(_) => HighlightTag::Constant,
263 hir::ModuleDef::Static(_) => HighlightTag::Constant, 265 hir::ModuleDef::Static(_) => HighlightTag::Static,
264 hir::ModuleDef::Trait(_) => HighlightTag::Trait, 266 hir::ModuleDef::Trait(_) => HighlightTag::Trait,
265 hir::ModuleDef::TypeAlias(_) => HighlightTag::TypeAlias, 267 hir::ModuleDef::TypeAlias(_) => HighlightTag::TypeAlias,
266 hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType, 268 hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType,
267 }, 269 },
268 NameDefinition::SelfType(_) => HighlightTag::TypeSelf, 270 NameDefinition::SelfType(_) => HighlightTag::SelfType,
269 NameDefinition::TypeParam(_) => HighlightTag::TypeParam, 271 NameDefinition::TypeParam(_) => HighlightTag::TypeParam,
272 // FIXME: distinguish between locals and parameters
270 NameDefinition::Local(local) => { 273 NameDefinition::Local(local) => {
271 let mut h = Highlight::new(HighlightTag::Variable); 274 let mut h = Highlight::new(HighlightTag::Local);
272 if local.is_mut(db) || local.ty(db).is_mutable_reference() { 275 if local.is_mut(db) || local.ty(db).is_mutable_reference() {
273 h |= HighlightModifier::Mutable; 276 h |= HighlightModifier::Mutable;
274 } 277 }
@@ -289,6 +292,7 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
289 match parent.kind() { 292 match parent.kind() {
290 STRUCT_DEF => HighlightTag::Struct.into(), 293 STRUCT_DEF => HighlightTag::Struct.into(),
291 ENUM_DEF => HighlightTag::Enum.into(), 294 ENUM_DEF => HighlightTag::Enum.into(),
295 UNION_KW => HighlightTag::Union.into(),
292 TRAIT_DEF => HighlightTag::Trait.into(), 296 TRAIT_DEF => HighlightTag::Trait.into(),
293 TYPE_ALIAS_DEF => HighlightTag::TypeAlias.into(), 297 TYPE_ALIAS_DEF => HighlightTag::TypeAlias.into(),
294 TYPE_PARAM => HighlightTag::TypeParam.into(), 298 TYPE_PARAM => HighlightTag::TypeParam.into(),
@@ -315,7 +319,7 @@ fn highlight_injection(
315 if let Some(range) = literal.open_quote_text_range() { 319 if let Some(range) = literal.open_quote_text_range() {
316 acc.push(HighlightedRange { 320 acc.push(HighlightedRange {
317 range, 321 range,
318 highlight: HighlightTag::LiteralString.into(), 322 highlight: HighlightTag::StringLiteral.into(),
319 binding_hash: None, 323 binding_hash: None,
320 }) 324 })
321 } 325 }
@@ -330,7 +334,7 @@ fn highlight_injection(
330 if let Some(range) = literal.close_quote_text_range() { 334 if let Some(range) = literal.close_quote_text_range() {
331 acc.push(HighlightedRange { 335 acc.push(HighlightedRange {
332 range, 336 range,
333 highlight: HighlightTag::LiteralString.into(), 337 highlight: HighlightTag::StringLiteral.into(),
334 binding_hash: None, 338 binding_hash: None,
335 }) 339 })
336 } 340 }
diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs
index df2fc3c48..0b12bdef5 100644
--- a/crates/ra_ide/src/syntax_highlighting/tags.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tags.rs
@@ -14,70 +14,71 @@ pub struct HighlightModifiers(u32);
14 14
15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 15#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
16pub enum HighlightTag { 16pub enum HighlightTag {
17 Struct, 17 Attribute,
18 Enum,
19 Union,
20 Trait,
21 TypeAlias,
22 BuiltinType, 18 BuiltinType,
23 19 ByteLiteral,
20 CharLiteral,
21 Comment,
22 Constant,
23 Enum,
24 EnumVariant,
24 Field, 25 Field,
25 Function, 26 Function,
26 Module, 27 Keyword,
27 Constant, 28 Lifetime,
28 Macro, 29 Macro,
29 Variable, 30 Module,
30 31 NumericLiteral,
31 TypeSelf, 32 SelfType,
33 Static,
34 StringLiteral,
35 Struct,
36 Trait,
37 TypeAlias,
32 TypeParam, 38 TypeParam,
33 TypeLifetime, 39 Union,
34 40 Local,
35 LiteralByte,
36 LiteralNumeric,
37 LiteralChar,
38
39 Comment,
40 LiteralString,
41 Attribute,
42
43 Keyword,
44} 41}
45 42
46#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 43#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
47#[repr(u8)] 44#[repr(u8)]
48pub enum HighlightModifier { 45pub enum HighlightModifier {
49 Mutable = 0,
50 Unsafe,
51 /// Used with keywords like `if` and `break`. 46 /// Used with keywords like `if` and `break`.
52 Control, 47 Control = 0,
48 /// `foo` in `fn foo(x: i32)` is a definition, `foo` in `foo(90 + 2)` is
49 /// not.
50 Definition,
51 Mutable,
52 Unsafe,
53} 53}
54 54
55impl HighlightTag { 55impl HighlightTag {
56 fn as_str(self) -> &'static str { 56 fn as_str(self) -> &'static str {
57 match self { 57 match self {
58 HighlightTag::Struct => "struct", 58 HighlightTag::Attribute => "attribute",
59 HighlightTag::Enum => "enum",
60 HighlightTag::Union => "union",
61 HighlightTag::Trait => "trait",
62 HighlightTag::TypeAlias => "type_alias",
63 HighlightTag::BuiltinType => "builtin_type", 59 HighlightTag::BuiltinType => "builtin_type",
64 60 HighlightTag::ByteLiteral => "byte_literal",
61 HighlightTag::CharLiteral => "char_literal",
62 HighlightTag::Comment => "comment",
63 HighlightTag::Constant => "constant",
64 HighlightTag::Enum => "enum",
65 HighlightTag::EnumVariant => "enum_variant",
65 HighlightTag::Field => "field", 66 HighlightTag::Field => "field",
66 HighlightTag::Function => "function", 67 HighlightTag::Function => "function",
67 HighlightTag::Module => "module",
68 HighlightTag::Constant => "constant",
69 HighlightTag::Macro => "macro",
70 HighlightTag::Variable => "variable",
71 HighlightTag::TypeSelf => "type.self",
72 HighlightTag::TypeParam => "type.param",
73 HighlightTag::TypeLifetime => "type.lifetime",
74 HighlightTag::LiteralByte => "literal.byte",
75 HighlightTag::LiteralNumeric => "literal.numeric",
76 HighlightTag::LiteralChar => "literal.char",
77 HighlightTag::Comment => "comment",
78 HighlightTag::LiteralString => "string",
79 HighlightTag::Attribute => "attribute",
80 HighlightTag::Keyword => "keyword", 68 HighlightTag::Keyword => "keyword",
69 HighlightTag::Lifetime => "lifetime",
70 HighlightTag::Macro => "macro",
71 HighlightTag::Module => "module",
72 HighlightTag::NumericLiteral => "numeric_literal",
73 HighlightTag::SelfType => "self_type",
74 HighlightTag::Static => "static",
75 HighlightTag::StringLiteral => "string",
76 HighlightTag::Struct => "struct",
77 HighlightTag::Trait => "trait",
78 HighlightTag::TypeAlias => "type_alias",
79 HighlightTag::TypeParam => "type_param",
80 HighlightTag::Union => "union",
81 HighlightTag::Local => "variable",
81 } 82 }
82 } 83 }
83} 84}
@@ -94,9 +95,10 @@ impl HighlightModifier {
94 95
95 fn as_str(self) -> &'static str { 96 fn as_str(self) -> &'static str {
96 match self { 97 match self {
98 HighlightModifier::Control => "control",
99 HighlightModifier::Definition => "declaration",
97 HighlightModifier::Mutable => "mutable", 100 HighlightModifier::Mutable => "mutable",
98 HighlightModifier::Unsafe => "unsafe", 101 HighlightModifier::Unsafe => "unsafe",
99 HighlightModifier::Control => "control",
100 } 102 }
101 } 103 }
102 104