Skip to content

Commit 51e82fe

Browse files
bors[bot]lnicola
andcommitted
Merge #1299
1299: Use ThemeColor and add support for light themes r=matklad a=lnicola Part of #1294. - switch to `ThemeColor` - add light and high contrast theme definitions - highlight control flow keywords and `unsafe` Co-authored-by: Laurențiu Nicola <[email protected]>
2 parents c6a5d87 + b08362f commit 51e82fe

File tree

3 files changed

+149
-14
lines changed

3 files changed

+149
-14
lines changed

crates/ra_ide_api/src/syntax_highlighting.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_hash::FxHashSet;
22

3-
use ra_syntax::{ast, AstNode, TextRange, Direction, SyntaxKind::*, SyntaxElement, T};
3+
use ra_syntax::{ast, AstNode, TextRange, Direction, SyntaxKind, SyntaxKind::*, SyntaxElement, T};
44
use ra_db::SourceDatabase;
55

66
use crate::{FileId, db::RootDatabase};
@@ -11,6 +11,21 @@ pub struct HighlightedRange {
1111
pub tag: &'static str,
1212
}
1313

14+
fn is_control_keyword(kind: SyntaxKind) -> bool {
15+
match kind {
16+
T![for]
17+
| T![loop]
18+
| T![while]
19+
| T![continue]
20+
| T![break]
21+
| T![if]
22+
| T![else]
23+
| T![match]
24+
| T![return] => true,
25+
_ => false,
26+
}
27+
}
28+
1429
pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> {
1530
let source_file = db.parse(file_id);
1631

@@ -29,6 +44,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
2944
NAME => "function",
3045
INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal",
3146
LIFETIME => "parameter",
47+
T![unsafe] => "keyword.unsafe",
48+
k if is_control_keyword(k) => "keyword.control",
3249
k if k.is_keyword() => "keyword",
3350
_ => {
3451
if let Some(macro_call) = node.as_node().and_then(ast::MacroCall::cast) {

editors/code/package.json

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,116 @@
268268
},
269269
"pattern": "$rustc"
270270
}
271+
],
272+
"colors": [
273+
{
274+
"id": "ralsp.comment",
275+
"description": "Color for comments",
276+
"defaults": {
277+
"dark": "#6A9955",
278+
"light": "#008000",
279+
"highContrast": "#7CA668"
280+
}
281+
},
282+
{
283+
"id": "ralsp.string",
284+
"description": "Color for strings",
285+
"defaults": {
286+
"dark": "#CE9178",
287+
"light": "#A31515",
288+
"highContrast": "#CE9178"
289+
}
290+
},
291+
{
292+
"id": "ralsp.keyword",
293+
"description": "Color for keywords",
294+
"defaults": {
295+
"dark": "#569cd6",
296+
"light": "#0000FF",
297+
"highContrast": "#569CD6"
298+
}
299+
},
300+
{
301+
"id": "ralsp.keyword.control",
302+
"description": "Color for control keywords",
303+
"defaults": {
304+
"dark": "#C586C0",
305+
"light": "#AF00DB",
306+
"highContrast": "#C586C0"
307+
}
308+
},
309+
{
310+
"id": "ralsp.keyword.unsafe",
311+
"description": "Color for unsafe",
312+
"defaults": {
313+
"dark": "#FF3030",
314+
"light": "#FF1010",
315+
"highContrast": "#FF1010"
316+
}
317+
},
318+
{
319+
"id": "ralsp.function",
320+
"description": "Color for functions",
321+
"defaults": {
322+
"dark": "#DCDCAA",
323+
"light": "#795E26",
324+
"highContrast": "#DCDCAA"
325+
}
326+
},
327+
{
328+
"id": "ralsp.parameter",
329+
"description": "Color for parameters",
330+
"defaults": {
331+
"dark": "#9CDCFE",
332+
"light": "#001080",
333+
"highContrast": "#9CDCFE"
334+
}
335+
},
336+
{
337+
"id": "ralsp.builtin",
338+
"description": "Color for builtins",
339+
"defaults": {
340+
"dark": "#DD6718",
341+
"light": "#DD6718",
342+
"highContrast": "#DD6718"
343+
}
344+
},
345+
{
346+
"id": "ralsp.text",
347+
"description": "Color for text",
348+
"defaults": {
349+
"dark": "#D4D4D4",
350+
"light": "#000000",
351+
"highContrast": "#FFFFFF"
352+
}
353+
},
354+
{
355+
"id": "ralsp.attribute",
356+
"description": "Color for attributes",
357+
"defaults": {
358+
"dark": "#9FE9BF",
359+
"light": "#1F4B1F",
360+
"highContrast": "#108010"
361+
}
362+
},
363+
{
364+
"id": "ralsp.literal",
365+
"description": "Color for literals",
366+
"defaults": {
367+
"dark": "#BECEA8",
368+
"light": "#09885A",
369+
"highContrast": "#B5CEA8"
370+
}
371+
},
372+
{
373+
"id": "ralsp.macro",
374+
"description": "Color for DFAF8F",
375+
"defaults": {
376+
"dark": "#BFEBBF",
377+
"light": "#DD6718",
378+
"highContrast": "#ED7718"
379+
}
380+
}
271381
]
272382
}
273383
}

editors/code/src/highlighting.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,31 @@ export class Highlighter {
1313
string,
1414
vscode.TextEditorDecorationType
1515
> {
16-
const decor = (color: string) =>
17-
vscode.window.createTextEditorDecorationType({ color });
16+
const colorContrib = (
17+
tag: string
18+
): [string, vscode.TextEditorDecorationType] => {
19+
const color = new vscode.ThemeColor('ralsp.' + tag);
20+
const decor = vscode.window.createTextEditorDecorationType({
21+
color
22+
});
23+
return [tag, decor];
24+
};
1825

1926
const decorations: Iterable<
2027
[string, vscode.TextEditorDecorationType]
2128
> = [
22-
['background', decor('#3F3F3F')],
23-
['comment', decor('#7F9F7F')],
24-
['string', decor('#CC9393')],
25-
['keyword', decor('#F0DFAF')],
26-
['function', decor('#93E0E3')],
27-
['parameter', decor('#94BFF3')],
28-
['builtin', decor('#DD6718')],
29-
['text', decor('#DCDCCC')],
30-
['attribute', decor('#BFEBBF')],
31-
['literal', decor('#DFAF8F')],
32-
['macro', decor('#DFAF8F')]
29+
colorContrib('comment'),
30+
colorContrib('string'),
31+
colorContrib('keyword'),
32+
colorContrib('keyword.control'),
33+
colorContrib('keyword.unsafe'),
34+
colorContrib('function'),
35+
colorContrib('parameter'),
36+
colorContrib('builtin'),
37+
colorContrib('text'),
38+
colorContrib('attribute'),
39+
colorContrib('literal'),
40+
colorContrib('macro')
3341
];
3442

3543
return new Map<string, vscode.TextEditorDecorationType>(decorations);

0 commit comments

Comments
 (0)