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.ts81
1 files changed, 29 insertions, 52 deletions
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index ee39ca64c..14199dbea 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -25,35 +25,15 @@ function fancify(seed: string, shade: 'light' | 'dark') {
25 return `hsl(${h},${s}%,${l}%)`; 25 return `hsl(${h},${s}%,${l}%)`;
26} 26}
27 27
28 28function createDecorationFromTextmate(
29function createDecorationFromTextmate(themeStyle: scopes.TextMateRuleSettings): vscode.TextEditorDecorationType { 29 themeStyle: scopes.TextMateRuleSettings
30 const options: vscode.DecorationRenderOptions = {}; 30): vscode.TextEditorDecorationType {
31 options.rangeBehavior = vscode.DecorationRangeBehavior.OpenOpen; 31 const decorationOptions: vscode.DecorationRenderOptions = {};
32 if (themeStyle.foreground) { 32 decorationOptions.rangeBehavior = vscode.DecorationRangeBehavior.OpenOpen;
33 options.color = themeStyle.foreground; 33 decorationOptions.color = themeStyle.foreground;
34 } 34 decorationOptions.backgroundColor = themeStyle.background;
35 if (themeStyle.background) { 35 decorationOptions.fontStyle = themeStyle.fontStyle;
36 options.backgroundColor = themeStyle.background; 36 return vscode.window.createTextEditorDecorationType(decorationOptions);
37 }
38 if (themeStyle.fontStyle) {
39 const parts: string[] = themeStyle.fontStyle.split(' ');
40 parts.forEach((part) => {
41 switch (part) {
42 case 'italic':
43 options.fontStyle = 'italic';
44 break;
45 case 'bold':
46 options.fontWeight = 'bold';
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} 37}
58 38
59export class Highlighter { 39export class Highlighter {
@@ -65,14 +45,12 @@ export class Highlighter {
65 tag: string, 45 tag: string,
66 textDecoration?: string 46 textDecoration?: string
67 ): [string, vscode.TextEditorDecorationType] => { 47 ): [string, vscode.TextEditorDecorationType] => {
68
69 const rule = scopesMapper.toRule(tag, scopes.find); 48 const rule = scopesMapper.toRule(tag, scopes.find);
70 49
71 if (rule) { 50 if (rule) {
72 const decor = createDecorationFromTextmate(rule); 51 const decor = createDecorationFromTextmate(rule);
73 return [tag, decor]; 52 return [tag, decor];
74 } 53 } else {
75 else {
76 const fallBackTag = 'ralsp.' + tag; 54 const fallBackTag = 'ralsp.' + tag;
77 // console.log(' '); 55 // console.log(' ');
78 // console.log('Missing theme for: <"' + tag + '"> for following mapped scopes:'); 56 // console.log('Missing theme for: <"' + tag + '"> for following mapped scopes:');
@@ -91,25 +69,25 @@ export class Highlighter {
91 const decorations: Iterable< 69 const decorations: Iterable<
92 [string, vscode.TextEditorDecorationType] 70 [string, vscode.TextEditorDecorationType]
93 > = [ 71 > = [
94 decoration('comment'), 72 decoration('comment'),
95 decoration('string'), 73 decoration('string'),
96 decoration('keyword'), 74 decoration('keyword'),
97 decoration('keyword.control'), 75 decoration('keyword.control'),
98 decoration('keyword.unsafe'), 76 decoration('keyword.unsafe'),
99 decoration('function'), 77 decoration('function'),
100 decoration('parameter'), 78 decoration('parameter'),
101 decoration('constant'), 79 decoration('constant'),
102 decoration('type'), 80 decoration('type'),
103 decoration('builtin'), 81 decoration('builtin'),
104 decoration('text'), 82 decoration('text'),
105 decoration('attribute'), 83 decoration('attribute'),
106 decoration('literal'), 84 decoration('literal'),
107 decoration('macro'), 85 decoration('macro'),
108 decoration('variable'), 86 decoration('variable'),
109 decoration('variable.mut', 'underline'), 87 decoration('variable.mut', 'underline'),
110 decoration('field'), 88 decoration('field'),
111 decoration('module') 89 decoration('module')
112 ]; 90 ];
113 91
114 return new Map<string, vscode.TextEditorDecorationType>(decorations); 92 return new Map<string, vscode.TextEditorDecorationType>(decorations);
115 } 93 }
@@ -138,7 +116,6 @@ export class Highlighter {
138 // Note: decoration objects need to be kept around so we can dispose them 116 // Note: decoration objects need to be kept around so we can dispose them
139 // if the user disables syntax highlighting 117 // if the user disables syntax highlighting
140 118
141
142 if (this.decorations == null) { 119 if (this.decorations == null) {
143 this.decorations = Highlighter.initDecorations(); 120 this.decorations = Highlighter.initDecorations();
144 } 121 }