aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/highlighting.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/highlighting.ts')
-rw-r--r--editors/code/src/highlighting.ts45
1 files changed, 28 insertions, 17 deletions
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index e2ac4d629..ceddffe0e 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -9,15 +9,24 @@ export interface Decoration {
9} 9}
10 10
11export class Highlighter { 11export class Highlighter {
12 private static initDecorations(): Map<string, vscode.TextEditorDecorationType> { 12 private static initDecorations(): Map<
13 const decor = (color: string) => vscode.window.createTextEditorDecorationType({ color }); 13 string,
14 vscode.TextEditorDecorationType
15 > {
16 const decor = (color: string) =>
17 vscode.window.createTextEditorDecorationType({ color });
14 18
15 const decorations: Iterable<[string, vscode.TextEditorDecorationType]> = [ 19 const decorations: Iterable<
20 [string, vscode.TextEditorDecorationType]
21 > = [
16 ['background', decor('#3F3F3F')], 22 ['background', decor('#3F3F3F')],
17 ['error', vscode.window.createTextEditorDecorationType({ 23 [
18 borderColor: 'red', 24 'error',
19 borderStyle: 'none none dashed none', 25 vscode.window.createTextEditorDecorationType({
20 })], 26 borderColor: 'red',
27 borderStyle: 'none none dashed none'
28 })
29 ],
21 ['comment', decor('#7F9F7F')], 30 ['comment', decor('#7F9F7F')],
22 ['string', decor('#CC9393')], 31 ['string', decor('#CC9393')],
23 ['keyword', decor('#F0DFAF')], 32 ['keyword', decor('#F0DFAF')],
@@ -26,13 +35,16 @@ export class Highlighter {
26 ['builtin', decor('#DD6718')], 35 ['builtin', decor('#DD6718')],
27 ['text', decor('#DCDCCC')], 36 ['text', decor('#DCDCCC')],
28 ['attribute', decor('#BFEBBF')], 37 ['attribute', decor('#BFEBBF')],
29 ['literal', decor('#DFAF8F')], 38 ['literal', decor('#DFAF8F')]
30 ]; 39 ];
31 40
32 return new Map<string, vscode.TextEditorDecorationType>(decorations); 41 return new Map<string, vscode.TextEditorDecorationType>(decorations);
33 } 42 }
34 43
35 private decorations: (Map<string, vscode.TextEditorDecorationType> | null) = null; 44 private decorations: Map<
45 string,
46 vscode.TextEditorDecorationType
47 > | null = null;
36 48
37 public removeHighlights() { 49 public removeHighlights() {
38 if (this.decorations == null) { 50 if (this.decorations == null) {
@@ -47,10 +59,7 @@ export class Highlighter {
47 this.decorations = null; 59 this.decorations = null;
48 } 60 }
49 61
50 public setHighlights( 62 public setHighlights(editor: vscode.TextEditor, highlights: Decoration[]) {
51 editor: vscode.TextEditor,
52 highlights: Decoration[],
53 ) {
54 // Initialize decorations if necessary 63 // Initialize decorations if necessary
55 // 64 //
56 // Note: decoration objects need to be kept around so we can dispose them 65 // Note: decoration objects need to be kept around so we can dispose them
@@ -68,13 +77,15 @@ export class Highlighter {
68 if (!byTag.get(d.tag)) { 77 if (!byTag.get(d.tag)) {
69 continue; 78 continue;
70 } 79 }
71 byTag.get(d.tag)!.push( 80 byTag
72 Server.client.protocol2CodeConverter.asRange(d.range), 81 .get(d.tag)!
73 ); 82 .push(Server.client.protocol2CodeConverter.asRange(d.range));
74 } 83 }
75 84
76 for (const tag of byTag.keys()) { 85 for (const tag of byTag.keys()) {
77 const dec = this.decorations.get(tag) as vscode.TextEditorDecorationType; 86 const dec = this.decorations.get(
87 tag
88 ) as vscode.TextEditorDecorationType;
78 const ranges = byTag.get(tag)!; 89 const ranges = byTag.get(tag)!;
79 editor.setDecorations(dec, ranges); 90 editor.setDecorations(dec, ranges);
80 } 91 }