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.ts99
1 files changed, 74 insertions, 25 deletions
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index d21d8a06a..dad99254e 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -1,6 +1,8 @@
1import seedrandom = require('seedrandom'); 1import seedrandom = require('seedrandom');
2import * as vscode from 'vscode'; 2import * as vscode from 'vscode';
3import * as lc from 'vscode-languageclient'; 3import * as lc from 'vscode-languageclient';
4import * as scopes from './scopes'
5import * as scopesMapper from './scopes_mapper';
4 6
5import { Server } from './server'; 7import { Server } from './server';
6 8
@@ -23,6 +25,37 @@ function fancify(seed: string, shade: 'light' | 'dark') {
23 return `hsl(${h},${s}%,${l}%)`; 25 return `hsl(${h},${s}%,${l}%)`;
24} 26}
25 27
28function createDecorationFromTextmate(themeStyle: scopes.TextMateRuleSettings): vscode.TextEditorDecorationType {
29 const options: vscode.DecorationRenderOptions = {}
30 options.rangeBehavior = vscode.DecorationRangeBehavior.OpenOpen
31 if (themeStyle.foreground) {
32 options.color = themeStyle.foreground
33 }
34 if (themeStyle.background) {
35 options.backgroundColor = themeStyle.background
36 }
37 if (themeStyle.fontStyle) {
38 const parts: string[] = themeStyle.fontStyle.split(' ')
39 parts.forEach((part) => {
40 switch (part) {
41 case 'italic':
42 options.fontStyle = 'italic'
43 break
44 case 'bold':
45 options.fontWeight = 'bold'
46
47 break
48 case 'underline':
49 options.textDecoration = 'underline'
50 break
51 default:
52 break
53 }
54 })
55 }
56 return vscode.window.createTextEditorDecorationType(options)
57}
58
26export class Highlighter { 59export class Highlighter {
27 private static initDecorations(): Map< 60 private static initDecorations(): Map<
28 string, 61 string,
@@ -32,36 +65,49 @@ export class Highlighter {
32 tag: string, 65 tag: string,
33 textDecoration?: string 66 textDecoration?: string
34 ): [string, vscode.TextEditorDecorationType] => { 67 ): [string, vscode.TextEditorDecorationType] => {
35 const color = new vscode.ThemeColor('ralsp.' + tag); 68
36 const decor = vscode.window.createTextEditorDecorationType({ 69 const rule = scopesMapper.toRule(tag, scopes.find)
37 color, 70
38 textDecoration 71 if (rule) {
39 }); 72 const decor = createDecorationFromTextmate(rule);
40 return [tag, decor]; 73 return [tag, decor];
74 }
75 else {
76 console.log(' ');
77 console.log('Missing theme for: <"' + tag + '"> for following mapped scopes:')
78 console.log(scopesMapper.find(tag))
79 console.log(' ');
80 const color = new vscode.ThemeColor('ralsp.' + tag);
81 const decor = vscode.window.createTextEditorDecorationType({
82 color,
83 textDecoration
84 });
85 return [tag, decor];
86 }
41 }; 87 };
42 88
43 const decorations: Iterable< 89 const decorations: Iterable<
44 [string, vscode.TextEditorDecorationType] 90 [string, vscode.TextEditorDecorationType]
45 > = [ 91 > = [
46 decoration('comment'), 92 decoration('comment'),
47 decoration('string'), 93 decoration('string'),
48 decoration('keyword'), 94 decoration('keyword'),
49 decoration('keyword.control'), 95 decoration('keyword.control'),
50 decoration('keyword.unsafe'), 96 decoration('keyword.unsafe'),
51 decoration('function'), 97 decoration('function'),
52 decoration('parameter'), 98 decoration('parameter'),
53 decoration('constant'), 99 decoration('constant'),
54 decoration('type'), 100 decoration('type'),
55 decoration('builtin'), 101 decoration('builtin'),
56 decoration('text'), 102 decoration('text'),
57 decoration('attribute'), 103 decoration('attribute'),
58 decoration('literal'), 104 decoration('literal'),
59 decoration('macro'), 105 decoration('macro'),
60 decoration('variable'), 106 decoration('variable'),
61 decoration('variable.mut', 'underline'), 107 decoration('variable.mut', 'underline'),
62 decoration('field'), 108 decoration('field'),
63 decoration('module') 109 decoration('module')
64 ]; 110 ];
65 111
66 return new Map<string, vscode.TextEditorDecorationType>(decorations); 112 return new Map<string, vscode.TextEditorDecorationType>(decorations);
67 } 113 }
@@ -89,6 +135,8 @@ export class Highlighter {
89 // 135 //
90 // Note: decoration objects need to be kept around so we can dispose them 136 // Note: decoration objects need to be kept around so we can dispose them
91 // if the user disables syntax highlighting 137 // if the user disables syntax highlighting
138
139
92 if (this.decorations == null) { 140 if (this.decorations == null) {
93 this.decorations = Highlighter.initDecorations(); 141 this.decorations = Highlighter.initDecorations();
94 } 142 }
@@ -133,6 +181,7 @@ export class Highlighter {
133 tag 181 tag
134 ) as vscode.TextEditorDecorationType; 182 ) as vscode.TextEditorDecorationType;
135 const ranges = byTag.get(tag)!; 183 const ranges = byTag.get(tag)!;
184
136 editor.setDecorations(dec, ranges); 185 editor.setDecorations(dec, ranges);
137 } 186 }
138 187