aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-02-28 13:48:42 +0000
committerGitHub <[email protected]>2020-02-28 13:48:42 +0000
commit2995fd2c87bba98d4cb7957a182a58bee68d86ba (patch)
tree9c8a33d167dbea0ffd0cb1460914542746905cad /crates/ra_ide/src
parent7e5cfcd4fb708f5d20a244ef010eaf57c055310d (diff)
parent9464ca97c90dca4cad57d29cac4fccdd99235925 (diff)
Merge #3363
3363: Cleanup highlighting tags r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/snapshots/highlighting.html54
-rw-r--r--crates/ra_ide/src/snapshots/rainbow_highlighting.html26
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs47
-rw-r--r--crates/ra_ide/src/syntax_highlighting/html.rs20
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tags.rs94
-rw-r--r--crates/ra_ide/src/syntax_highlighting/tests.rs2
6 files changed, 132 insertions, 111 deletions
diff --git a/crates/ra_ide/src/snapshots/highlighting.html b/crates/ra_ide/src/snapshots/highlighting.html
index 51851763e..8c372ad27 100644
--- a/crates/ra_ide/src/snapshots/highlighting.html
+++ b/crates/ra_ide/src/snapshots/highlighting.html
@@ -3,70 +3,72 @@
3body { margin: 0; } 3body { margin: 0; }
4pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; } 4pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
5 5
6
6.comment { color: #7F9F7F; } 7.comment { color: #7F9F7F; }
7.string { color: #CC9393; } 8.struct, .enum { color: #7CB8BB; }
9.enum_variant { color: #BDE0F3; }
10.string_literal { color: #CC9393; }
8.field { color: #94BFF3; } 11.field { color: #94BFF3; }
9.function { color: #93E0E3; } 12.function { color: #93E0E3; }
10.parameter { color: #94BFF3; } 13.parameter { color: #94BFF3; }
11.text { color: #DCDCCC; } 14.text { color: #DCDCCC; }
12.type { color: #7CB8BB; } 15.type { color: #7CB8BB; }
13.type.builtin { color: #8CD0D3; } 16.builtin_type { color: #8CD0D3; }
14.type.param { color: #20999D; } 17.type_param { color: #DFAF8F; }
15.attribute { color: #94BFF3; } 18.attribute { color: #94BFF3; }
16.literal { color: #BFEBBF; } 19.numeric_literal { color: #BFEBBF; }
17.literal.numeric { color: #6A8759; }
18.macro { color: #94BFF3; } 20.macro { color: #94BFF3; }
19.module { color: #AFD8AF; } 21.module { color: #AFD8AF; }
20.variable { color: #DCDCCC; } 22.variable { color: #DCDCCC; }
21.variable.mut { color: #DCDCCC; text-decoration: underline; } 23.mutable { text-decoration: underline; }
22 24
23.keyword { color: #F0DFAF; } 25.keyword { color: #F0DFAF; font-weight: bold; }
24.keyword.unsafe { color: #DFAF8F; } 26.keyword.unsafe { color: #BC8383; font-weight: bold; }
25.keyword.control { color: #F0DFAF; font-weight: bold; } 27.control { font-style: italic; }
26</style> 28</style>
27<pre><code><span class="attribute">#</span><span class="attribute">[</span><span class="attribute">derive</span><span class="attribute">(</span><span class="attribute">Clone</span><span class="attribute">,</span><span class="attribute"> </span><span class="attribute">Debug</span><span class="attribute">)</span><span class="attribute">]</span> 29<pre><code><span class="attribute">#</span><span class="attribute">[</span><span class="attribute">derive</span><span class="attribute">(</span><span class="attribute">Clone</span><span class="attribute">,</span><span class="attribute"> </span><span class="attribute">Debug</span><span class="attribute">)</span><span class="attribute">]</span>
28<span class="keyword">struct</span> <span class="type">Foo</span> { 30<span class="keyword">struct</span> <span class="struct">Foo</span> {
29 <span class="keyword">pub</span> <span class="field">x</span>: <span class="type builtin">i32</span>, 31 <span class="keyword">pub</span> <span class="field">x</span>: <span class="builtin_type">i32</span>,
30 <span class="keyword">pub</span> <span class="field">y</span>: <span class="type builtin">i32</span>, 32 <span class="keyword">pub</span> <span class="field">y</span>: <span class="builtin_type">i32</span>,
31} 33}
32 34
33<span class="keyword">fn</span> <span class="function">foo</span>&lt;<span class="type param">T</span>&gt;() -&gt; <span class="type param">T</span> { 35<span class="keyword">fn</span> <span class="function">foo</span>&lt;<span class="type_param">T</span>&gt;() -&gt; <span class="type_param">T</span> {
34 <span class="macro">unimplemented</span><span class="macro">!</span>(); 36 <span class="macro">unimplemented</span><span class="macro">!</span>();
35 <span class="function">foo</span>::&lt;<span class="type builtin">i32</span>&gt;(); 37 <span class="function">foo</span>::&lt;<span class="builtin_type">i32</span>&gt;();
36} 38}
37 39
38<span class="macro">macro_rules</span><span class="macro">!</span> def_fn { 40<span class="macro">macro_rules</span><span class="macro">!</span> def_fn {
39 ($($tt:tt)*) =&gt; {$($tt)*} 41 ($($tt:tt)*) =&gt; {$($tt)*}
40} 42}
41 43
42<span class="macro">def_fn</span><span class="macro">!</span>{ 44<span class="macro">def_fn</span><span class="macro">!</span> {
43 <span class="keyword">fn</span> <span class="function">bar</span>() -&gt; <span class="type builtin">u32</span> { 45 <span class="keyword">fn</span> <span class="function">bar</span>() -&gt; <span class="builtin_type">u32</span> {
44 <span class="literal numeric">100</span> 46 <span class="numeric_literal">100</span>
45 } 47 }
46} 48}
47 49
48<span class="comment">// comment</span> 50<span class="comment">// comment</span>
49<span class="keyword">fn</span> <span class="function">main</span>() { 51<span class="keyword">fn</span> <span class="function">main</span>() {
50 <span class="macro">println</span><span class="macro">!</span>(<span class="string">"Hello, {}!"</span>, <span class="literal numeric">92</span>); 52 <span class="macro">println</span><span class="macro">!</span>(<span class="string_literal">"Hello, {}!"</span>, <span class="numeric_literal">92</span>);
51 53
52 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable">vec</span> = Vec::new(); 54 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable">vec</span> = Vec::new();
53 <span class="keyword control">if</span> <span class="keyword">true</span> { 55 <span class="keyword control">if</span> <span class="keyword">true</span> {
54 <span class="keyword">let</span> <span class="variable">x</span> = <span class="literal numeric">92</span>; 56 <span class="keyword">let</span> <span class="variable">x</span> = <span class="numeric_literal">92</span>;
55 <span class="variable mutable">vec</span>.push(<span class="type">Foo</span> { <span class="field">x</span>, <span class="field">y</span>: <span class="literal numeric">1</span> }); 57 <span class="variable mutable">vec</span>.push(<span class="struct">Foo</span> { <span class="field">x</span>, <span class="field">y</span>: <span class="numeric_literal">1</span> });
56 } 58 }
57 <span class="keyword unsafe">unsafe</span> { <span class="variable mutable">vec</span>.set_len(<span class="literal numeric">0</span>); } 59 <span class="keyword unsafe">unsafe</span> { <span class="variable mutable">vec</span>.set_len(<span class="numeric_literal">0</span>); }
58 60
59 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable">x</span> = <span class="literal numeric">42</span>; 61 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable">x</span> = <span class="numeric_literal">42</span>;
60 <span class="keyword">let</span> <span class="variable mutable">y</span> = &<span class="keyword">mut</span> <span class="variable mutable">x</span>; 62 <span class="keyword">let</span> <span class="variable mutable">y</span> = &<span class="keyword">mut</span> <span class="variable mutable">x</span>;
61 <span class="keyword">let</span> <span class="variable">z</span> = &<span class="variable mutable">y</span>; 63 <span class="keyword">let</span> <span class="variable">z</span> = &<span class="variable mutable">y</span>;
62 64
63 <span class="variable mutable">y</span>; 65 <span class="variable mutable">y</span>;
64} 66}
65 67
66<span class="keyword">enum</span> <span class="type">E</span>&lt;<span class="type param">X</span>&gt; { 68<span class="keyword">enum</span> <span class="enum">E</span>&lt;<span class="type_param">X</span>&gt; {
67 <span class="constant">V</span>(<span class="type param">X</span>) 69 <span class="enum_variant">V</span>(<span class="type_param">X</span>)
68} 70}
69 71
70<span class="keyword">impl</span>&lt;<span class="type param">X</span>&gt; <span class="type">E</span>&lt;<span class="type param">X</span>&gt; { 72<span class="keyword">impl</span>&lt;<span class="type_param">X</span>&gt; <span class="enum">E</span>&lt;<span class="type_param">X</span>&gt; {
71 <span class="keyword">fn</span> <span class="function">new</span>&lt;<span class="type param">T</span>&gt;() -&gt; <span class="type">E</span>&lt;<span class="type param">T</span>&gt; {} 73 <span class="keyword">fn</span> <span class="function">new</span>&lt;<span class="type_param">T</span>&gt;() -&gt; <span class="enum">E</span>&lt;<span class="type_param">T</span>&gt; {}
72}</code></pre> \ No newline at end of file 74}</code></pre> \ No newline at end of file
diff --git a/crates/ra_ide/src/snapshots/rainbow_highlighting.html b/crates/ra_ide/src/snapshots/rainbow_highlighting.html
index 1f869867f..f63e64b6d 100644
--- a/crates/ra_ide/src/snapshots/rainbow_highlighting.html
+++ b/crates/ra_ide/src/snapshots/rainbow_highlighting.html
@@ -3,36 +3,38 @@
3body { margin: 0; } 3body { margin: 0; }
4pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; } 4pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
5 5
6
6.comment { color: #7F9F7F; } 7.comment { color: #7F9F7F; }
7.string { color: #CC9393; } 8.struct, .enum { color: #7CB8BB; }
9.enum_variant { color: #BDE0F3; }
10.string_literal { color: #CC9393; }
8.field { color: #94BFF3; } 11.field { color: #94BFF3; }
9.function { color: #93E0E3; } 12.function { color: #93E0E3; }
10.parameter { color: #94BFF3; } 13.parameter { color: #94BFF3; }
11.text { color: #DCDCCC; } 14.text { color: #DCDCCC; }
12.type { color: #7CB8BB; } 15.type { color: #7CB8BB; }
13.type.builtin { color: #8CD0D3; } 16.builtin_type { color: #8CD0D3; }
14.type.param { color: #20999D; } 17.type_param { color: #DFAF8F; }
15.attribute { color: #94BFF3; } 18.attribute { color: #94BFF3; }
16.literal { color: #BFEBBF; } 19.numeric_literal { color: #BFEBBF; }
17.literal.numeric { color: #6A8759; }
18.macro { color: #94BFF3; } 20.macro { color: #94BFF3; }
19.module { color: #AFD8AF; } 21.module { color: #AFD8AF; }
20.variable { color: #DCDCCC; } 22.variable { color: #DCDCCC; }
21.variable.mut { color: #DCDCCC; text-decoration: underline; } 23.mutable { text-decoration: underline; }
22 24
23.keyword { color: #F0DFAF; } 25.keyword { color: #F0DFAF; font-weight: bold; }
24.keyword.unsafe { color: #DFAF8F; } 26.keyword.unsafe { color: #BC8383; font-weight: bold; }
25.keyword.control { color: #F0DFAF; font-weight: bold; } 27.control { font-style: italic; }
26</style> 28</style>
27<pre><code><span class="keyword">fn</span> <span class="function">main</span>() { 29<pre><code><span class="keyword">fn</span> <span class="function">main</span>() {
28 <span class="keyword">let</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string">"hello"</span>; 30 <span class="keyword">let</span> <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string_literal">"hello"</span>;
29 <span class="keyword">let</span> <span class="variable" data-binding-hash="2705725358298919760" style="color: hsl(17,51%,74%);">x</span> = <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span>.to_string(); 31 <span class="keyword">let</span> <span class="variable" data-binding-hash="2705725358298919760" style="color: hsl(17,51%,74%);">x</span> = <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span>.to_string();
30 <span class="keyword">let</span> <span class="variable" data-binding-hash="3365759661443752373" style="color: hsl(127,76%,66%);">y</span> = <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span>.to_string(); 32 <span class="keyword">let</span> <span class="variable" data-binding-hash="3365759661443752373" style="color: hsl(127,76%,66%);">y</span> = <span class="variable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span>.to_string();
31 33
32 <span class="keyword">let</span> <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span> = <span class="string">"other color please!"</span>; 34 <span class="keyword">let</span> <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span> = <span class="string_literal">"other color please!"</span>;
33 <span class="keyword">let</span> <span class="variable" data-binding-hash="6717528807933952652" style="color: hsl(85,49%,84%);">y</span> = <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span>.to_string(); 35 <span class="keyword">let</span> <span class="variable" data-binding-hash="6717528807933952652" style="color: hsl(85,49%,84%);">y</span> = <span class="variable" data-binding-hash="794745962933817518" style="color: hsl(19,74%,76%);">x</span>.to_string();
34} 36}
35 37
36<span class="keyword">fn</span> <span class="function">bar</span>() { 38<span class="keyword">fn</span> <span class="function">bar</span>() {
37 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string">"hello"</span>; 39 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable mutable" data-binding-hash="8121853618659664005" style="color: hsl(261,57%,61%);">hello</span> = <span class="string_literal">"hello"</span>;
38}</code></pre> \ No newline at end of file 40}</code></pre> \ No newline at end of file
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index d7bca1193..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);
@@ -255,20 +257,21 @@ fn highlight_name(db: &RootDatabase, def: NameDefinition) -> Highlight {
255 NameDefinition::ModuleDef(def) => match def { 257 NameDefinition::ModuleDef(def) => match def {
256 hir::ModuleDef::Module(_) => HighlightTag::Module, 258 hir::ModuleDef::Module(_) => HighlightTag::Module,
257 hir::ModuleDef::Function(_) => HighlightTag::Function, 259 hir::ModuleDef::Function(_) => HighlightTag::Function,
258 hir::ModuleDef::Adt(_) => HighlightTag::Type, 260 hir::ModuleDef::Adt(hir::Adt::Struct(_)) => HighlightTag::Struct,
259 hir::ModuleDef::EnumVariant(_) => HighlightTag::Constant, 261 hir::ModuleDef::Adt(hir::Adt::Enum(_)) => HighlightTag::Enum,
262 hir::ModuleDef::Adt(hir::Adt::Union(_)) => HighlightTag::Union,
263 hir::ModuleDef::EnumVariant(_) => HighlightTag::EnumVariant,
260 hir::ModuleDef::Const(_) => HighlightTag::Constant, 264 hir::ModuleDef::Const(_) => HighlightTag::Constant,
261 hir::ModuleDef::Static(_) => HighlightTag::Constant, 265 hir::ModuleDef::Static(_) => HighlightTag::Static,
262 hir::ModuleDef::Trait(_) => HighlightTag::Type, 266 hir::ModuleDef::Trait(_) => HighlightTag::Trait,
263 hir::ModuleDef::TypeAlias(_) => HighlightTag::Type, 267 hir::ModuleDef::TypeAlias(_) => HighlightTag::TypeAlias,
264 hir::ModuleDef::BuiltinType(_) => { 268 hir::ModuleDef::BuiltinType(_) => HighlightTag::BuiltinType,
265 return HighlightTag::Type | HighlightModifier::Builtin
266 }
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 }
@@ -287,7 +290,11 @@ fn highlight_name_by_syntax(name: ast::Name) -> Highlight {
287 }; 290 };
288 291
289 match parent.kind() { 292 match parent.kind() {
290 STRUCT_DEF | ENUM_DEF | TRAIT_DEF | TYPE_ALIAS_DEF => HighlightTag::Type.into(), 293 STRUCT_DEF => HighlightTag::Struct.into(),
294 ENUM_DEF => HighlightTag::Enum.into(),
295 UNION_KW => HighlightTag::Union.into(),
296 TRAIT_DEF => HighlightTag::Trait.into(),
297 TYPE_ALIAS_DEF => HighlightTag::TypeAlias.into(),
291 TYPE_PARAM => HighlightTag::TypeParam.into(), 298 TYPE_PARAM => HighlightTag::TypeParam.into(),
292 RECORD_FIELD_DEF => HighlightTag::Field.into(), 299 RECORD_FIELD_DEF => HighlightTag::Field.into(),
293 _ => default, 300 _ => default,
@@ -312,7 +319,7 @@ fn highlight_injection(
312 if let Some(range) = literal.open_quote_text_range() { 319 if let Some(range) = literal.open_quote_text_range() {
313 acc.push(HighlightedRange { 320 acc.push(HighlightedRange {
314 range, 321 range,
315 highlight: HighlightTag::LiteralString.into(), 322 highlight: HighlightTag::StringLiteral.into(),
316 binding_hash: None, 323 binding_hash: None,
317 }) 324 })
318 } 325 }
@@ -327,7 +334,7 @@ fn highlight_injection(
327 if let Some(range) = literal.close_quote_text_range() { 334 if let Some(range) = literal.close_quote_text_range() {
328 acc.push(HighlightedRange { 335 acc.push(HighlightedRange {
329 range, 336 range,
330 highlight: HighlightTag::LiteralString.into(), 337 highlight: HighlightTag::StringLiteral.into(),
331 binding_hash: None, 338 binding_hash: None,
332 }) 339 })
333 } 340 }
diff --git a/crates/ra_ide/src/syntax_highlighting/html.rs b/crates/ra_ide/src/syntax_highlighting/html.rs
index 210d9a57b..54678c278 100644
--- a/crates/ra_ide/src/syntax_highlighting/html.rs
+++ b/crates/ra_ide/src/syntax_highlighting/html.rs
@@ -80,25 +80,27 @@ const STYLE: &str = "
80body { margin: 0; } 80body { margin: 0; }
81pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; } 81pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padding: 0.4em; }
82 82
83
83.comment { color: #7F9F7F; } 84.comment { color: #7F9F7F; }
84.string { color: #CC9393; } 85.struct, .enum { color: #7CB8BB; }
86.enum_variant { color: #BDE0F3; }
87.string_literal { color: #CC9393; }
85.field { color: #94BFF3; } 88.field { color: #94BFF3; }
86.function { color: #93E0E3; } 89.function { color: #93E0E3; }
87.parameter { color: #94BFF3; } 90.parameter { color: #94BFF3; }
88.text { color: #DCDCCC; } 91.text { color: #DCDCCC; }
89.type { color: #7CB8BB; } 92.type { color: #7CB8BB; }
90.type.builtin { color: #8CD0D3; } 93.builtin_type { color: #8CD0D3; }
91.type.param { color: #20999D; } 94.type_param { color: #DFAF8F; }
92.attribute { color: #94BFF3; } 95.attribute { color: #94BFF3; }
93.literal { color: #BFEBBF; } 96.numeric_literal { color: #BFEBBF; }
94.literal.numeric { color: #6A8759; }
95.macro { color: #94BFF3; } 97.macro { color: #94BFF3; }
96.module { color: #AFD8AF; } 98.module { color: #AFD8AF; }
97.variable { color: #DCDCCC; } 99.variable { color: #DCDCCC; }
98.variable.mut { color: #DCDCCC; text-decoration: underline; } 100.mutable { text-decoration: underline; }
99 101
100.keyword { color: #F0DFAF; } 102.keyword { color: #F0DFAF; font-weight: bold; }
101.keyword.unsafe { color: #DFAF8F; } 103.keyword.unsafe { color: #BC8383; font-weight: bold; }
102.keyword.control { color: #F0DFAF; font-weight: bold; } 104.control { font-style: italic; }
103</style> 105</style>
104"; 106";
diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs
index 383c74c98..9da80823c 100644
--- a/crates/ra_ide/src/syntax_highlighting/tags.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tags.rs
@@ -14,59 +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 Attribute,
18 BuiltinType,
19 ByteLiteral,
20 CharLiteral,
21 Comment,
22 Constant,
23 Enum,
24 EnumVariant,
17 Field, 25 Field,
18 Function, 26 Function,
19 Module, 27 Keyword,
20 Constant, 28 Lifetime,
21 Macro, 29 Macro,
22 Variable, 30 Module,
23 31 NumericLiteral,
24 Type, 32 SelfType,
25 TypeSelf, 33 Static,
34 StringLiteral,
35 Struct,
36 Trait,
37 TypeAlias,
26 TypeParam, 38 TypeParam,
27 TypeLifetime, 39 Union,
28 40 Local,
29 LiteralByte,
30 LiteralNumeric,
31 LiteralChar,
32
33 Comment,
34 LiteralString,
35 Attribute,
36
37 Keyword,
38} 41}
39 42
40#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] 43#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
41#[repr(u8)] 44#[repr(u8)]
42pub enum HighlightModifier { 45pub enum HighlightModifier {
43 Mutable = 0,
44 Unsafe,
45 /// Used with keywords like `if` and `break`. 46 /// Used with keywords like `if` and `break`.
46 Control, 47 Control = 0,
47 Builtin, 48 /// `foo` in `fn foo(x: i32)` is a definition, `foo` in `foo(90 + 2)` is
49 /// not.
50 Definition,
51 Mutable,
52 Unsafe,
48} 53}
49 54
50impl HighlightTag { 55impl HighlightTag {
51 fn as_str(self) -> &'static str { 56 fn as_str(self) -> &'static str {
52 match self { 57 match self {
58 HighlightTag::Attribute => "attribute",
59 HighlightTag::BuiltinType => "builtin_type",
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",
53 HighlightTag::Field => "field", 66 HighlightTag::Field => "field",
54 HighlightTag::Function => "function", 67 HighlightTag::Function => "function",
55 HighlightTag::Module => "module",
56 HighlightTag::Constant => "constant",
57 HighlightTag::Macro => "macro",
58 HighlightTag::Variable => "variable",
59 HighlightTag::Type => "type",
60 HighlightTag::TypeSelf => "type.self",
61 HighlightTag::TypeParam => "type.param",
62 HighlightTag::TypeLifetime => "type.lifetime",
63 HighlightTag::LiteralByte => "literal.byte",
64 HighlightTag::LiteralNumeric => "literal.numeric",
65 HighlightTag::LiteralChar => "literal.char",
66 HighlightTag::Comment => "comment",
67 HighlightTag::LiteralString => "string",
68 HighlightTag::Attribute => "attribute",
69 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_literal",
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",
70 } 82 }
71 } 83 }
72} 84}
@@ -78,19 +90,15 @@ impl fmt::Display for HighlightTag {
78} 90}
79 91
80impl HighlightModifier { 92impl HighlightModifier {
81 const ALL: &'static [HighlightModifier] = &[ 93 const ALL: &'static [HighlightModifier] =
82 HighlightModifier::Mutable, 94 &[HighlightModifier::Mutable, HighlightModifier::Unsafe, HighlightModifier::Control];
83 HighlightModifier::Unsafe,
84 HighlightModifier::Control,
85 HighlightModifier::Builtin,
86 ];
87 95
88 fn as_str(self) -> &'static str { 96 fn as_str(self) -> &'static str {
89 match self { 97 match self {
98 HighlightModifier::Control => "control",
99 HighlightModifier::Definition => "declaration",
90 HighlightModifier::Mutable => "mutable", 100 HighlightModifier::Mutable => "mutable",
91 HighlightModifier::Unsafe => "unsafe", 101 HighlightModifier::Unsafe => "unsafe",
92 HighlightModifier::Control => "control",
93 HighlightModifier::Builtin => "builtin",
94 } 102 }
95 } 103 }
96 104
diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs
index ff23d4ac5..2d90a072f 100644
--- a/crates/ra_ide/src/syntax_highlighting/tests.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tests.rs
@@ -26,7 +26,7 @@ macro_rules! def_fn {
26 ($($tt:tt)*) => {$($tt)*} 26 ($($tt:tt)*) => {$($tt)*}
27} 27}
28 28
29def_fn!{ 29def_fn! {
30 fn bar() -> u32 { 30 fn bar() -> u32 {
31 100 31 100
32 } 32 }