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.ts62
1 files changed, 56 insertions, 6 deletions
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index e1b0d13e7..4e224a54c 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,41 @@ 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(
29 themeStyle: scopes.TextMateRuleSettings,
30): vscode.TextEditorDecorationType {
31 const decorationOptions: vscode.DecorationRenderOptions = {};
32 decorationOptions.rangeBehavior = vscode.DecorationRangeBehavior.OpenOpen;
33
34 if (themeStyle.foreground) {
35 decorationOptions.color = themeStyle.foreground;
36 }
37
38 if (themeStyle.background) {
39 decorationOptions.backgroundColor = themeStyle.background;
40 }
41
42 if (themeStyle.fontStyle) {
43 const parts: string[] = themeStyle.fontStyle.split(' ');
44 parts.forEach(part => {
45 switch (part) {
46 case 'italic':
47 decorationOptions.fontStyle = 'italic';
48 break;
49 case 'bold':
50 decorationOptions.fontWeight = 'bold';
51 break;
52 case 'underline':
53 decorationOptions.textDecoration = 'underline';
54 break;
55 default:
56 break;
57 }
58 });
59 }
60 return vscode.window.createTextEditorDecorationType(decorationOptions);
61}
62
26export class Highlighter { 63export class Highlighter {
27 private static initDecorations(): Map< 64 private static initDecorations(): Map<
28 string, 65 string,
@@ -32,12 +69,25 @@ export class Highlighter {
32 tag: string, 69 tag: string,
33 textDecoration?: string, 70 textDecoration?: string,
34 ): [string, vscode.TextEditorDecorationType] => { 71 ): [string, vscode.TextEditorDecorationType] => {
35 const color = new vscode.ThemeColor('ralsp.' + tag); 72 const rule = scopesMapper.toRule(tag, scopes.find);
36 const decor = vscode.window.createTextEditorDecorationType({ 73
37 color, 74 if (rule) {
38 textDecoration, 75 const decor = createDecorationFromTextmate(rule);
39 }); 76 return [tag, decor];
40 return [tag, decor]; 77 } else {
78 const fallBackTag = 'ralsp.' + tag;
79 // console.log(' ');
80 // console.log('Missing theme for: <"' + tag + '"> for following mapped scopes:');
81 // console.log(scopesMapper.find(tag));
82 // console.log('Falling back to values defined in: ' + fallBackTag);
83 // console.log(' ');
84 const color = new vscode.ThemeColor(fallBackTag);
85 const decor = vscode.window.createTextEditorDecorationType({
86 color,
87 textDecoration,
88 });
89 return [tag, decor];
90 }
41 }; 91 };
42 92
43 const decorations: Iterable<[ 93 const decorations: Iterable<[