aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--crates/ra_ide_db/src/defs.rs4
-rw-r--r--crates/rust-analyzer/src/conv.rs42
-rw-r--r--crates/rust-analyzer/src/semantic_tokens.rs18
-rw-r--r--editors/code/package.json87
10 files changed, 233 insertions, 161 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..c0f7c1c9f 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_DEF => 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 }
diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs
index e10e72f71..484755158 100644
--- a/crates/ra_ide_db/src/defs.rs
+++ b/crates/ra_ide_db/src/defs.rs
@@ -90,6 +90,10 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option
90 let def: hir::Struct = sema.to_def(&it)?; 90 let def: hir::Struct = sema.to_def(&it)?;
91 Some(from_module_def(def.into())) 91 Some(from_module_def(def.into()))
92 }, 92 },
93 ast::UnionDef(it) => {
94 let def: hir::Union = sema.to_def(&it)?;
95 Some(from_module_def(def.into()))
96 },
93 ast::EnumDef(it) => { 97 ast::EnumDef(it) => {
94 let def: hir::Enum = sema.to_def(&it)?; 98 let def: hir::Enum = sema.to_def(&it)?;
95 Some(from_module_def(def.into())) 99 Some(from_module_def(def.into()))
diff --git a/crates/rust-analyzer/src/conv.rs b/crates/rust-analyzer/src/conv.rs
index b012f5dd5..ff156307a 100644
--- a/crates/rust-analyzer/src/conv.rs
+++ b/crates/rust-analyzer/src/conv.rs
@@ -20,11 +20,11 @@ use ra_vfs::LineEndings;
20 20
21use crate::{ 21use crate::{
22 req, 22 req,
23 semantic_tokens::{self, ModifierSet, BUILTIN, CONSTANT, CONTROL, MUTABLE, UNSAFE}, 23 semantic_tokens::{self, ModifierSet, CONSTANT, CONTROL, MUTABLE, UNSAFE},
24 world::WorldSnapshot, 24 world::WorldSnapshot,
25 Result, 25 Result,
26}; 26};
27use semantic_tokens::ATTRIBUTE; 27use semantic_tokens::{ATTRIBUTE, BUILTIN_TYPE, ENUM_MEMBER, LIFETIME, TYPE_ALIAS, UNION};
28 28
29pub trait Conv { 29pub trait Conv {
30 type Output; 30 type Output;
@@ -316,41 +316,43 @@ impl Conv for Highlight {
316 fn conv(self) -> Self::Output { 316 fn conv(self) -> Self::Output {
317 let mut mods = ModifierSet::default(); 317 let mut mods = ModifierSet::default();
318 let type_ = match self.tag { 318 let type_ = match self.tag {
319 HighlightTag::Struct => SemanticTokenType::STRUCT,
320 HighlightTag::Enum => SemanticTokenType::ENUM,
321 HighlightTag::Union => UNION,
322 HighlightTag::TypeAlias => TYPE_ALIAS,
323 HighlightTag::Trait => SemanticTokenType::INTERFACE,
324 HighlightTag::BuiltinType => BUILTIN_TYPE,
325 HighlightTag::SelfType => SemanticTokenType::TYPE,
319 HighlightTag::Field => SemanticTokenType::MEMBER, 326 HighlightTag::Field => SemanticTokenType::MEMBER,
320 HighlightTag::Function => SemanticTokenType::FUNCTION, 327 HighlightTag::Function => SemanticTokenType::FUNCTION,
321 HighlightTag::Module => SemanticTokenType::NAMESPACE, 328 HighlightTag::Module => SemanticTokenType::NAMESPACE,
322 HighlightTag::Constant => { 329 HighlightTag::Constant => {
330 mods |= CONSTANT;
323 mods |= SemanticTokenModifier::STATIC; 331 mods |= SemanticTokenModifier::STATIC;
324 mods |= SemanticTokenModifier::READONLY; 332 SemanticTokenType::VARIABLE
325 CONSTANT
326 } 333 }
327 HighlightTag::Macro => SemanticTokenType::MACRO, 334 HighlightTag::Static => {
328 HighlightTag::Variable => SemanticTokenType::VARIABLE, 335 mods |= SemanticTokenModifier::STATIC;
329 HighlightTag::Type => SemanticTokenType::TYPE, 336 SemanticTokenType::VARIABLE
330 HighlightTag::TypeSelf => {
331 mods |= SemanticTokenModifier::REFERENCE;
332 SemanticTokenType::TYPE
333 } 337 }
338 HighlightTag::EnumVariant => ENUM_MEMBER,
339 HighlightTag::Macro => SemanticTokenType::MACRO,
340 HighlightTag::Local => SemanticTokenType::VARIABLE,
334 HighlightTag::TypeParam => SemanticTokenType::TYPE_PARAMETER, 341 HighlightTag::TypeParam => SemanticTokenType::TYPE_PARAMETER,
335 HighlightTag::TypeLifetime => { 342 HighlightTag::Lifetime => LIFETIME,
336 mods |= SemanticTokenModifier::REFERENCE; 343 HighlightTag::ByteLiteral | HighlightTag::NumericLiteral => SemanticTokenType::NUMBER,
337 SemanticTokenType::LABEL 344 HighlightTag::CharLiteral | HighlightTag::StringLiteral => SemanticTokenType::STRING,
338 }
339 HighlightTag::LiteralByte => SemanticTokenType::NUMBER,
340 HighlightTag::LiteralNumeric => SemanticTokenType::NUMBER,
341 HighlightTag::LiteralChar => SemanticTokenType::NUMBER,
342 HighlightTag::Comment => SemanticTokenType::COMMENT, 345 HighlightTag::Comment => SemanticTokenType::COMMENT,
343 HighlightTag::LiteralString => SemanticTokenType::STRING,
344 HighlightTag::Attribute => ATTRIBUTE, 346 HighlightTag::Attribute => ATTRIBUTE,
345 HighlightTag::Keyword => SemanticTokenType::KEYWORD, 347 HighlightTag::Keyword => SemanticTokenType::KEYWORD,
346 }; 348 };
347 349
348 for modifier in self.modifiers.iter() { 350 for modifier in self.modifiers.iter() {
349 let modifier = match modifier { 351 let modifier = match modifier {
352 HighlightModifier::Definition => SemanticTokenModifier::DECLARATION,
353 HighlightModifier::Control => CONTROL,
350 HighlightModifier::Mutable => MUTABLE, 354 HighlightModifier::Mutable => MUTABLE,
351 HighlightModifier::Unsafe => UNSAFE, 355 HighlightModifier::Unsafe => UNSAFE,
352 HighlightModifier::Control => CONTROL,
353 HighlightModifier::Builtin => BUILTIN,
354 }; 356 };
355 mods |= modifier; 357 mods |= modifier;
356 } 358 }
diff --git a/crates/rust-analyzer/src/semantic_tokens.rs b/crates/rust-analyzer/src/semantic_tokens.rs
index d8362409d..1b146e4d8 100644
--- a/crates/rust-analyzer/src/semantic_tokens.rs
+++ b/crates/rust-analyzer/src/semantic_tokens.rs
@@ -5,12 +5,16 @@ use std::ops;
5use lsp_types::{Range, SemanticToken, SemanticTokenModifier, SemanticTokenType}; 5use lsp_types::{Range, SemanticToken, SemanticTokenModifier, SemanticTokenType};
6 6
7pub(crate) const ATTRIBUTE: SemanticTokenType = SemanticTokenType::new("attribute"); 7pub(crate) const ATTRIBUTE: SemanticTokenType = SemanticTokenType::new("attribute");
8pub(crate) const CONSTANT: SemanticTokenType = SemanticTokenType::new("constant"); 8pub(crate) const BUILTIN_TYPE: SemanticTokenType = SemanticTokenType::new("builtinType");
9pub(crate) const ENUM_MEMBER: SemanticTokenType = SemanticTokenType::new("enumMember");
10pub(crate) const LIFETIME: SemanticTokenType = SemanticTokenType::new("lifetime");
11pub(crate) const TYPE_ALIAS: SemanticTokenType = SemanticTokenType::new("typeAlias");
12pub(crate) const UNION: SemanticTokenType = SemanticTokenType::new("union");
9 13
14pub(crate) const CONSTANT: SemanticTokenModifier = SemanticTokenModifier::new("constant");
15pub(crate) const CONTROL: SemanticTokenModifier = SemanticTokenModifier::new("control");
10pub(crate) const MUTABLE: SemanticTokenModifier = SemanticTokenModifier::new("mutable"); 16pub(crate) const MUTABLE: SemanticTokenModifier = SemanticTokenModifier::new("mutable");
11pub(crate) const UNSAFE: SemanticTokenModifier = SemanticTokenModifier::new("unsafe"); 17pub(crate) const UNSAFE: SemanticTokenModifier = SemanticTokenModifier::new("unsafe");
12pub(crate) const CONTROL: SemanticTokenModifier = SemanticTokenModifier::new("control");
13pub(crate) const BUILTIN: SemanticTokenModifier = SemanticTokenModifier::new("builtin");
14 18
15pub(crate) const SUPPORTED_TYPES: &[SemanticTokenType] = &[ 19pub(crate) const SUPPORTED_TYPES: &[SemanticTokenType] = &[
16 SemanticTokenType::COMMENT, 20 SemanticTokenType::COMMENT,
@@ -34,7 +38,11 @@ pub(crate) const SUPPORTED_TYPES: &[SemanticTokenType] = &[
34 SemanticTokenType::PARAMETER, 38 SemanticTokenType::PARAMETER,
35 SemanticTokenType::LABEL, 39 SemanticTokenType::LABEL,
36 ATTRIBUTE, 40 ATTRIBUTE,
37 CONSTANT, 41 BUILTIN_TYPE,
42 ENUM_MEMBER,
43 LIFETIME,
44 TYPE_ALIAS,
45 UNION,
38]; 46];
39 47
40pub(crate) const SUPPORTED_MODIFIERS: &[SemanticTokenModifier] = &[ 48pub(crate) const SUPPORTED_MODIFIERS: &[SemanticTokenModifier] = &[
@@ -48,10 +56,10 @@ pub(crate) const SUPPORTED_MODIFIERS: &[SemanticTokenModifier] = &[
48 SemanticTokenModifier::ASYNC, 56 SemanticTokenModifier::ASYNC,
49 SemanticTokenModifier::VOLATILE, 57 SemanticTokenModifier::VOLATILE,
50 SemanticTokenModifier::READONLY, 58 SemanticTokenModifier::READONLY,
59 CONSTANT,
51 MUTABLE, 60 MUTABLE,
52 UNSAFE, 61 UNSAFE,
53 CONTROL, 62 CONTROL,
54 BUILTIN,
55]; 63];
56 64
57#[derive(Default)] 65#[derive(Default)]
diff --git a/editors/code/package.json b/editors/code/package.json
index e484467b0..862de3210 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -155,11 +155,6 @@
155 "when": "editorTextFocus && editorLangId == rust" 155 "when": "editorTextFocus && editorLangId == rust"
156 }, 156 },
157 { 157 {
158 "command": "rust-analyzer.run",
159 "key": "ctrl+r",
160 "when": "editorTextFocus && editorLangId == rust"
161 },
162 {
163 "command": "rust-analyzer.onEnter", 158 "command": "rust-analyzer.onEnter",
164 "key": "enter", 159 "key": "enter",
165 "when": "editorTextFocus && !suggestWidgetVisible && editorLangId == rust && !vim.active || vim.mode == 'Insert' && editorTextFocus && !suggestWidgetVisible && editorLangId == rust" 160 "when": "editorTextFocus && !suggestWidgetVisible && editorLangId == rust && !vim.active || vim.mode == 'Insert' && editorTextFocus && !suggestWidgetVisible && editorLangId == rust"
@@ -405,24 +400,42 @@
405 ], 400 ],
406 "semanticTokenTypes": [ 401 "semanticTokenTypes": [
407 { 402 {
408 "id": "attribute" 403 "id": "attribute",
404 "description": "Style for attributes"
405 },
406 {
407 "id": "builtinType",
408 "description": "Style for builtin types"
409 }, 409 },
410 { 410 {
411 "id": "constant" 411 "id": "lifetime",
412 "description": "Style for lifetimes"
413 },
414 {
415 "id": "typeAlias",
416 "description": "Style for type aliases"
417 },
418 {
419 "id": "union",
420 "description": "Style for C-style untagged unions"
412 } 421 }
413 ], 422 ],
414 "semanticTokenModifiers": [ 423 "semanticTokenModifiers": [
415 { 424 {
416 "id": "mutable" 425 "id": "constant",
426 "description": "Style for compile-time constants"
417 }, 427 },
418 { 428 {
419 "id": "unsafe" 429 "id": "control",
430 "description": "Style for control flow keywords"
420 }, 431 },
421 { 432 {
422 "id": "control" 433 "id": "mutable",
434 "description": "Style for mutable bindings"
423 }, 435 },
424 { 436 {
425 "id": "builtin" 437 "id": "unsafe",
438 "description": "Style for unsafe operations"
426 } 439 }
427 ], 440 ],
428 "semanticTokenStyleDefaults": [ 441 "semanticTokenStyleDefaults": [
@@ -433,21 +446,27 @@
433 ] 446 ]
434 }, 447 },
435 { 448 {
436 "selector": "*.mutable", 449 "selector": "builtinType",
437 "light": { 450 "scope": [
438 "fontStyle": "underline" 451 "support.type.primitive"
439 }, 452 ]
440 "dark": {
441 "fontStyle": "underline"
442 },
443 "highContrast": {
444 "fontStyle": "underline"
445 }
446 }, 453 },
447 { 454 {
448 "selector": "constant", 455 "selector": "lifetime",
449 "scope": [ 456 "scope": [
450 "entity.name.constant" 457 "entity.name.lifetime.rust"
458 ]
459 },
460 {
461 "selector": "typeAlias",
462 "scope": [
463 "entity.name.typeAlias"
464 ]
465 },
466 {
467 "selector": "union",
468 "scope": [
469 "entity.name.union"
451 ] 470 ]
452 }, 471 },
453 { 472 {
@@ -457,10 +476,28 @@
457 ] 476 ]
458 }, 477 },
459 { 478 {
460 "selector": "type.builtin", 479 "selector": "keyword.control",
480 "scope": [
481 "keyword.control"
482 ]
483 },
484 {
485 "selector": "variable.constant",
461 "scope": [ 486 "scope": [
462 "support.type.builtin" 487 "entity.name.constant"
463 ] 488 ]
489 },
490 {
491 "selector": "*.mutable",
492 "light": {
493 "fontStyle": "underline"
494 },
495 "dark": {
496 "fontStyle": "underline"
497 },
498 "highContrast": {
499 "fontStyle": "underline"
500 }
464 } 501 }
465 ] 502 ]
466 } 503 }