aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide_api/src/syntax_highlighting.rs12
-rw-r--r--editors/code/package.json119
-rw-r--r--editors/code/src/highlighting.ts35
3 files changed, 152 insertions, 14 deletions
diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs
index a03b13839..ab69a4374 100644
--- a/crates/ra_ide_api/src/syntax_highlighting.rs
+++ b/crates/ra_ide_api/src/syntax_highlighting.rs
@@ -1,6 +1,6 @@
1use rustc_hash::FxHashSet; 1use rustc_hash::FxHashSet;
2 2
3use ra_syntax::{ast, AstNode, TextRange, Direction, SyntaxKind::*, SyntaxElement, T}; 3use ra_syntax::{ast, AstNode, TextRange, Direction, SyntaxKind, SyntaxKind::*, SyntaxElement, T};
4use ra_db::SourceDatabase; 4use ra_db::SourceDatabase;
5 5
6use crate::{FileId, db::RootDatabase}; 6use crate::{FileId, db::RootDatabase};
@@ -11,6 +11,14 @@ pub struct HighlightedRange {
11 pub tag: &'static str, 11 pub tag: &'static str,
12} 12}
13 13
14fn is_control_keyword(kind: SyntaxKind) -> bool {
15 match kind {
16 FOR_KW | LOOP_KW | WHILE_KW | CONTINUE_KW | BREAK_KW | IF_KW | ELSE_KW | MATCH_KW
17 | RETURN_KW => true,
18 _ => false,
19 }
20}
21
14pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> { 22pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> {
15 let source_file = db.parse(file_id); 23 let source_file = db.parse(file_id);
16 24
@@ -29,6 +37,8 @@ pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRa
29 NAME => "function", 37 NAME => "function",
30 INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal", 38 INT_NUMBER | FLOAT_NUMBER | CHAR | BYTE => "literal",
31 LIFETIME => "parameter", 39 LIFETIME => "parameter",
40 UNSAFE_KW => "unsafe",
41 k if is_control_keyword(k) => "control",
32 k if k.is_keyword() => "keyword", 42 k if k.is_keyword() => "keyword",
33 _ => { 43 _ => {
34 if let Some(macro_call) = node.as_node().and_then(ast::MacroCall::cast) { 44 if let Some(macro_call) = node.as_node().and_then(ast::MacroCall::cast) {
diff --git a/editors/code/package.json b/editors/code/package.json
index 015b912b3..c72037da9 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -268,6 +268,125 @@
268 }, 268 },
269 "pattern": "$rustc" 269 "pattern": "$rustc"
270 } 270 }
271 ],
272 "colors": [
273 {
274 "id": "ralsp.background",
275 "description": "Background color",
276 "defaults": {
277 "dark": "#3F3F3F",
278 "light": "#001080",
279 "highContrast": "#000000"
280 }
281 },
282 {
283 "id": "ralsp.comment",
284 "description": "Color for comments",
285 "defaults": {
286 "dark": "#7F9F7F",
287 "light": "#008000",
288 "highContrast": "#7CA668"
289 }
290 },
291 {
292 "id": "ralsp.string",
293 "description": "Color for strings",
294 "defaults": {
295 "dark": "#CC9393",
296 "light": "#A31515",
297 "highContrast": "#CE9178"
298 }
299 },
300 {
301 "id": "ralsp.unsafe",
302 "description": "Color for unsafe",
303 "defaults": {
304 "dark": "#FF3030",
305 "light": "#FF1010",
306 "highContrast": "#FF1010"
307 }
308 },
309 {
310 "id": "ralsp.keyword",
311 "description": "Color for keywords",
312 "defaults": {
313 "dark": "#F0DFAF",
314 "light": "#0000FF",
315 "highContrast": "#569CD6"
316 }
317 },
318 {
319 "id": "ralsp.control",
320 "description": "Color for control keywords",
321 "defaults": {
322 "dark": "#CF20FB",
323 "light": "#AF00DB",
324 "highContrast": "#C586C0"
325 }
326 },
327 {
328 "id": "ralsp.function",
329 "description": "Color for functions",
330 "defaults": {
331 "dark": "#93E0E3",
332 "light": "#795E26",
333 "highContrast": "#DCDCAA"
334 }
335 },
336 {
337 "id": "ralsp.parameter",
338 "description": "Color for parameters",
339 "defaults": {
340 "dark": "#94BFF3",
341 "light": "#001080",
342 "highContrast": "#9CDCFE"
343 }
344 },
345 {
346 "id": "ralsp.builtin",
347 "description": "Color for builtins",
348 "defaults": {
349 "dark": "#DD6718",
350 "light": "#DD6718",
351 "highContrast": "#DD6718"
352 }
353 },
354 {
355 "id": "ralsp.text",
356 "description": "Color for text",
357 "defaults": {
358 "dark": "#DCDCCC",
359 "light": "#000000",
360 "highContrast": "#FFFFFF"
361 }
362 },
363 {
364 "id": "ralsp.attribute",
365 "description": "Color for attributes",
366 "defaults": {
367 "dark": "#BFEBBF",
368 "light": "#1F4B1F",
369 "highContrast": "#108010"
370 }
371 },
372 {
373 "id": "ralsp.literal",
374 "description": "Color for literals",
375 "defaults": {
376 "dark": "#DFAF8F",
377 "light": "#09885A",
378 "highContrast": "#B5CEA8"
379 }
380 },
381 {
382 "id": "ralsp.macro",
383 "description": "Color for DFAF8F",
384 "defaults": {
385 "dark": "#BFEBBF",
386 "light": "#DD6718",
387 "highContrast": "#ED7718"
388 }
389 }
271 ] 390 ]
272 } 391 }
273} 392}
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index 2521dff62..432f40ff4 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -13,23 +13,32 @@ export class Highlighter {
13 string, 13 string,
14 vscode.TextEditorDecorationType 14 vscode.TextEditorDecorationType
15 > { 15 > {
16 const decor = (color: string) => 16 const colorContrib = (
17 vscode.window.createTextEditorDecorationType({ color }); 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 };
18 25
19 const decorations: Iterable< 26 const decorations: Iterable<
20 [string, vscode.TextEditorDecorationType] 27 [string, vscode.TextEditorDecorationType]
21 > = [ 28 > = [
22 ['background', decor('#3F3F3F')], 29 colorContrib('background'),
23 ['comment', decor('#7F9F7F')], 30 colorContrib('comment'),
24 ['string', decor('#CC9393')], 31 colorContrib('string'),
25 ['keyword', decor('#F0DFAF')], 32 colorContrib('unsafe'),
26 ['function', decor('#93E0E3')], 33 colorContrib('keyword'),
27 ['parameter', decor('#94BFF3')], 34 colorContrib('control'),
28 ['builtin', decor('#DD6718')], 35 colorContrib('function'),
29 ['text', decor('#DCDCCC')], 36 colorContrib('parameter'),
30 ['attribute', decor('#BFEBBF')], 37 colorContrib('builtin'),
31 ['literal', decor('#DFAF8F')], 38 colorContrib('text'),
32 ['macro', decor('#DFAF8F')] 39 colorContrib('attribute'),
40 colorContrib('literal'),
41 colorContrib('macro')
33 ]; 42 ];
34 43
35 return new Map<string, vscode.TextEditorDecorationType>(decorations); 44 return new Map<string, vscode.TextEditorDecorationType>(decorations);