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.ts96
1 files changed, 71 insertions, 25 deletions
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index d21d8a06a..b7dffaff5 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,46 @@ 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('Missing theme for: ' + tag);
77 const color = new vscode.ThemeColor('ralsp.' + tag);
78 const decor = vscode.window.createTextEditorDecorationType({
79 color,
80 textDecoration
81 });
82 return [tag, decor];
83 }
41 }; 84 };
42 85
43 const decorations: Iterable< 86 const decorations: Iterable<
44 [string, vscode.TextEditorDecorationType] 87 [string, vscode.TextEditorDecorationType]
45 > = [ 88 > = [
46 decoration('comment'), 89 decoration('comment'),
47 decoration('string'), 90 decoration('string'),
48 decoration('keyword'), 91 decoration('keyword'),
49 decoration('keyword.control'), 92 decoration('keyword.control'),
50 decoration('keyword.unsafe'), 93 decoration('keyword.unsafe'),
51 decoration('function'), 94 decoration('function'),
52 decoration('parameter'), 95 decoration('parameter'),
53 decoration('constant'), 96 decoration('constant'),
54 decoration('type'), 97 decoration('type'),
55 decoration('builtin'), 98 decoration('builtin'),
56 decoration('text'), 99 decoration('text'),
57 decoration('attribute'), 100 decoration('attribute'),
58 decoration('literal'), 101 decoration('literal'),
59 decoration('macro'), 102 decoration('macro'),
60 decoration('variable'), 103 decoration('variable'),
61 decoration('variable.mut', 'underline'), 104 decoration('variable.mut', 'underline'),
62 decoration('field'), 105 decoration('field'),
63 decoration('module') 106 decoration('module')
64 ]; 107 ];
65 108
66 return new Map<string, vscode.TextEditorDecorationType>(decorations); 109 return new Map<string, vscode.TextEditorDecorationType>(decorations);
67 } 110 }
@@ -89,6 +132,8 @@ export class Highlighter {
89 // 132 //
90 // Note: decoration objects need to be kept around so we can dispose them 133 // Note: decoration objects need to be kept around so we can dispose them
91 // if the user disables syntax highlighting 134 // if the user disables syntax highlighting
135
136
92 if (this.decorations == null) { 137 if (this.decorations == null) {
93 this.decorations = Highlighter.initDecorations(); 138 this.decorations = Highlighter.initDecorations();
94 } 139 }
@@ -133,6 +178,7 @@ export class Highlighter {
133 tag 178 tag
134 ) as vscode.TextEditorDecorationType; 179 ) as vscode.TextEditorDecorationType;
135 const ranges = byTag.get(tag)!; 180 const ranges = byTag.get(tag)!;
181
136 editor.setDecorations(dec, ranges); 182 editor.setDecorations(dec, ranges);
137 } 183 }
138 184