aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide/src/snapshots/highlighting.html26
-rw-r--r--crates/ra_ide/src/syntax_highlighting.rs16
-rw-r--r--editors/code/package.json65
-rw-r--r--editors/code/src/highlighting.ts7
4 files changed, 96 insertions, 18 deletions
diff --git a/crates/ra_ide/src/snapshots/highlighting.html b/crates/ra_ide/src/snapshots/highlighting.html
index 4166a8f90..40605d9ef 100644
--- a/crates/ra_ide/src/snapshots/highlighting.html
+++ b/crates/ra_ide/src/snapshots/highlighting.html
@@ -10,8 +10,10 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
10.builtin { color: #DD6718; } 10.builtin { color: #DD6718; }
11.text { color: #DCDCCC; } 11.text { color: #DCDCCC; }
12.type { color: #7CB8BB; } 12.type { color: #7CB8BB; }
13.type\.param { color: #20999D; }
13.attribute { color: #94BFF3; } 14.attribute { color: #94BFF3; }
14.literal { color: #BFEBBF; } 15.literal { color: #BFEBBF; }
16.literal\.numeric { color: #6A8759; }
15.macro { color: #94BFF3; } 17.macro { color: #94BFF3; }
16.variable { color: #DCDCCC; } 18.variable { color: #DCDCCC; }
17.variable\.mut { color: #DCDCCC; text-decoration: underline; } 19.variable\.mut { color: #DCDCCC; text-decoration: underline; }
@@ -22,36 +24,36 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
22</style> 24</style>
23<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> 25<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>
24<span class="keyword">struct</span> <span class="type">Foo</span> { 26<span class="keyword">struct</span> <span class="type">Foo</span> {
25 <span class="keyword">pub</span> <span class="field">x</span>: <span class="type">i32</span>, 27 <span class="keyword">pub</span> <span class="field">x</span>: <span class="type.builtin">i32</span>,
26 <span class="keyword">pub</span> <span class="field">y</span>: <span class="type">i32</span>, 28 <span class="keyword">pub</span> <span class="field">y</span>: <span class="type.builtin">i32</span>,
27} 29}
28 30
29<span class="keyword">fn</span> <span class="function">foo</span>&lt;<span class="type">T</span>&gt;() -&gt; <span class="type">T</span> { 31<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> {
30 <span class="macro">unimplemented</span><span class="macro">!</span>(); 32 <span class="macro">unimplemented</span><span class="macro">!</span>();
31 <span class="function">foo</span>::&lt;<span class="type">i32</span>&gt;(); 33 <span class="function">foo</span>::&lt;<span class="type.builtin">i32</span>&gt;();
32} 34}
33 35
34<span class="comment">// comment</span> 36<span class="comment">// comment</span>
35<span class="keyword">fn</span> <span class="function">main</span>() { 37<span class="keyword">fn</span> <span class="function">main</span>() {
36 <span class="macro">println</span><span class="macro">!</span>(<span class="string">"Hello, {}!"</span>, <span class="literal">92</span>); 38 <span class="macro">println</span><span class="macro">!</span>(<span class="string">"Hello, {}!"</span>, <span class="literal.numeric">92</span>);
37 39
38 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable.mut">vec</span> = <span class="text">Vec</span>::<span class="text">new</span>(); 40 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable.mut">vec</span> = <span class="text">Vec</span>::<span class="text">new</span>();
39 <span class="keyword.control">if</span> <span class="keyword">true</span> { 41 <span class="keyword.control">if</span> <span class="keyword">true</span> {
40 <span class="variable.mut">vec</span>.<span class="text">push</span>(<span class="type">Foo</span> { <span class="field">x</span>: <span class="literal">0</span>, <span class="field">y</span>: <span class="literal">1</span> }); 42 <span class="variable.mut">vec</span>.<span class="text">push</span>(<span class="type">Foo</span> { <span class="field">x</span>: <span class="literal.numeric">0</span>, <span class="field">y</span>: <span class="literal.numeric">1</span> });
41 } 43 }
42 <span class="keyword.unsafe">unsafe</span> { <span class="variable.mut">vec</span>.<span class="text">set_len</span>(<span class="literal">0</span>); } 44 <span class="keyword.unsafe">unsafe</span> { <span class="variable.mut">vec</span>.<span class="text">set_len</span>(<span class="literal.numeric">0</span>); }
43 45
44 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable.mut">x</span> = <span class="literal">42</span>; 46 <span class="keyword">let</span> <span class="keyword">mut</span> <span class="variable.mut">x</span> = <span class="literal.numeric">42</span>;
45 <span class="keyword">let</span> <span class="variable.mut">y</span> = &<span class="keyword">mut</span> <span class="variable.mut">x</span>; 47 <span class="keyword">let</span> <span class="variable.mut">y</span> = &<span class="keyword">mut</span> <span class="variable.mut">x</span>;
46 <span class="keyword">let</span> <span class="variable">z</span> = &<span class="variable.mut">y</span>; 48 <span class="keyword">let</span> <span class="variable">z</span> = &<span class="variable.mut">y</span>;
47 49
48 <span class="variable.mut">y</span>; 50 <span class="variable.mut">y</span>;
49} 51}
50 52
51<span class="keyword">enum</span> <span class="type">E</span>&lt;<span class="type">X</span>&gt; { 53<span class="keyword">enum</span> <span class="type">E</span>&lt;<span class="type.param">X</span>&gt; {
52 <span class="constant">V</span>(<span class="type">X</span>) 54 <span class="constant">V</span>(<span class="type.param">X</span>)
53} 55}
54 56
55<span class="keyword">impl</span>&lt;<span class="type">X</span>&gt; <span class="type">E</span>&lt;<span class="type">X</span>&gt; { 57<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; {
56 <span class="keyword">fn</span> <span class="function">new</span>&lt;<span class="type">T</span>&gt;() -&gt; <span class="type">E</span>&lt;<span class="type">T</span>&gt; {} 58 <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; {}
57}</code></pre> \ No newline at end of file 59}</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 7ecb1a027..235e09ffc 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -108,14 +108,17 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
108 match name_kind { 108 match name_kind {
109 Some(name_kind) => highlight_name(db, name_kind), 109 Some(name_kind) => highlight_name(db, name_kind),
110 None => name.syntax().parent().map_or("function", |x| match x.kind() { 110 None => name.syntax().parent().map_or("function", |x| match x.kind() {
111 TYPE_PARAM | STRUCT_DEF | ENUM_DEF | TRAIT_DEF | TYPE_ALIAS_DEF => "type", 111 STRUCT_DEF | ENUM_DEF | TRAIT_DEF | TYPE_ALIAS_DEF => "type",
112 TYPE_PARAM => "type.param",
112 RECORD_FIELD_DEF => "field", 113 RECORD_FIELD_DEF => "field",
113 _ => "function", 114 _ => "function",
114 }), 115 }),
115 } 116 }
116 } 117 }
117 INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal", 118 INT_NUMBER | FLOAT_NUMBER => "literal.numeric",
118 LIFETIME => "parameter", 119 BYTE => "literal.byte",
120 CHAR => "literal.char",
121 LIFETIME => "type.lifetime",
119 T![unsafe] => "keyword.unsafe", 122 T![unsafe] => "keyword.unsafe",
120 k if is_control_keyword(k) => "keyword.control", 123 k if is_control_keyword(k) => "keyword.control",
121 k if k.is_keyword() => "keyword", 124 k if k.is_keyword() => "keyword",
@@ -224,8 +227,9 @@ fn highlight_name(db: &RootDatabase, name_kind: NameKind) -> &'static str {
224 Def(hir::ModuleDef::Static(_)) => "constant", 227 Def(hir::ModuleDef::Static(_)) => "constant",
225 Def(hir::ModuleDef::Trait(_)) => "type", 228 Def(hir::ModuleDef::Trait(_)) => "type",
226 Def(hir::ModuleDef::TypeAlias(_)) => "type", 229 Def(hir::ModuleDef::TypeAlias(_)) => "type",
227 Def(hir::ModuleDef::BuiltinType(_)) => "type", 230 Def(hir::ModuleDef::BuiltinType(_)) => "type.builtin",
228 SelfType(_) | TypeParam(_) => "type", 231 SelfType(_) => "type.self",
232 TypeParam(_) => "type.param",
229 Local(local) => { 233 Local(local) => {
230 if local.is_mut(db) { 234 if local.is_mut(db) {
231 "variable.mut" 235 "variable.mut"
@@ -255,8 +259,10 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
255.builtin { color: #DD6718; } 259.builtin { color: #DD6718; }
256.text { color: #DCDCCC; } 260.text { color: #DCDCCC; }
257.type { color: #7CB8BB; } 261.type { color: #7CB8BB; }
262.type\\.param { color: #20999D; }
258.attribute { color: #94BFF3; } 263.attribute { color: #94BFF3; }
259.literal { color: #BFEBBF; } 264.literal { color: #BFEBBF; }
265.literal\\.numeric { color: #6A8759; }
260.macro { color: #94BFF3; } 266.macro { color: #94BFF3; }
261.variable { color: #DCDCCC; } 267.variable { color: #DCDCCC; }
262.variable\\.mut { color: #DCDCCC; text-decoration: underline; } 268.variable\\.mut { color: #DCDCCC; text-decoration: underline; }
diff --git a/editors/code/package.json b/editors/code/package.json
index e3bb07be7..43db61a8b 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -438,6 +438,33 @@
438 } 438 }
439 }, 439 },
440 { 440 {
441 "id": "ralsp.literal.numeric",
442 "description": "Color for numeric literals",
443 "defaults": {
444 "dark": "#BECEA8",
445 "light": "#09885A",
446 "highContrast": "#B5CEA8"
447 }
448 },
449 {
450 "id": "ralsp.literal.char",
451 "description": "Color for character literals",
452 "defaults": {
453 "dark": "#BECEA8",
454 "light": "#09885A",
455 "highContrast": "#B5CEA8"
456 }
457 },
458 {
459 "id": "ralsp.literal.byte",
460 "description": "Color for byte literals",
461 "defaults": {
462 "dark": "#BECEA8",
463 "light": "#09885A",
464 "highContrast": "#B5CEA8"
465 }
466 },
467 {
441 "id": "ralsp.macro", 468 "id": "ralsp.macro",
442 "description": "Color for macros", 469 "description": "Color for macros",
443 "defaults": { 470 "defaults": {
@@ -457,7 +484,43 @@
457 }, 484 },
458 { 485 {
459 "id": "ralsp.type", 486 "id": "ralsp.type",
460 "description": "Color for types", 487 "description": "Color for other types (traits, aliases..)",
488 "defaults": {
489 "dark": "#4EC9B0",
490 "light": "#267F99",
491 "highContrast": "#4EC9B0"
492 }
493 },
494 {
495 "id": "ralsp.type.builtin",
496 "description": "Color for built-in types (&str, bool, u16, u32)",
497 "defaults": {
498 "dark": "#4EC9B0",
499 "light": "#267F99",
500 "highContrast": "#4EC9B0"
501 }
502 },
503 {
504 "id": "ralsp.type.lifetime",
505 "description": "Color for `Self` param type",
506 "defaults": {
507 "dark": "#4EC9B0",
508 "light": "#267F99",
509 "highContrast": "#4EC9B0"
510 }
511 },
512 {
513 "id": "ralsp.type.self",
514 "description": "Color for `Self` param type",
515 "defaults": {
516 "dark": "#4EC9B0",
517 "light": "#267F99",
518 "highContrast": "#4EC9B0"
519 }
520 },
521 {
522 "id": "ralsp.type.param",
523 "description": "Color for type parameters",
461 "defaults": { 524 "defaults": {
462 "dark": "#4EC9B0", 525 "dark": "#4EC9B0",
463 "light": "#267F99", 526 "light": "#267F99",
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index 6d50a2f2d..d7c0ae131 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -53,10 +53,17 @@ export class Highlighter {
53 decoration('parameter'), 53 decoration('parameter'),
54 decoration('constant'), 54 decoration('constant'),
55 decoration('type'), 55 decoration('type'),
56 decoration('type.self'),
57 decoration('type.generic'),
58 decoration('type.param'),
59 decoration('type.lifetime'),
56 decoration('builtin'), 60 decoration('builtin'),
57 decoration('text'), 61 decoration('text'),
58 decoration('attribute'), 62 decoration('attribute'),
59 decoration('literal'), 63 decoration('literal'),
64 decoration('literal.numeric'),
65 decoration('literal.char'),
66 decoration('literal.byte'),
60 decoration('macro'), 67 decoration('macro'),
61 decoration('variable'), 68 decoration('variable'),
62 decoration('variable.mut', 'underline'), 69 decoration('variable.mut', 'underline'),