aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/highlighting.ts
diff options
context:
space:
mode:
authorSeivan Heidari <[email protected]>2019-11-04 22:59:11 +0000
committerSeivan Heidari <[email protected]>2019-11-04 22:59:11 +0000
commitc60f9bf4c6d6ddd341c673b228b6aa1add3da62b (patch)
treee411904c533ac37745397719bbfe983aeb21b372 /editors/code/src/highlighting.ts
parentdad9bc6caad71e6aebb92ad9883c08d30431e9b1 (diff)
* Adding scope mapping configuration manifest in `package.json`
* Loading configurable scope mappings from settings. * Updating Readme with `rust-analyzer.scopeMappings`. `rust-analyzer.scopeMappings` -- a scheme backed JSON object to tweak Rust Analyzer scopes to TextMate scopes. ```jsonc { //Will autocomplete keys to available RA scopes. "keyword.unsafe": ["keyword", "keyword.control"], //Values are string | TextMateScope | [string | TextMateScope] "comments": "comment.block" } ```
Diffstat (limited to 'editors/code/src/highlighting.ts')
-rw-r--r--editors/code/src/highlighting.ts32
1 files changed, 16 insertions, 16 deletions
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index dad99254e..1c67e5dc3 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -1,7 +1,7 @@
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' 4import * as scopes from './scopes';
5import * as scopesMapper from './scopes_mapper'; 5import * as scopesMapper from './scopes_mapper';
6 6
7import { Server } from './server'; 7import { Server } from './server';
@@ -25,35 +25,35 @@ 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(themeStyle: scopes.TextMateRuleSettings): vscode.TextEditorDecorationType { 29function createDecorationFromTextmate(themeStyle: scopes.TextMateRuleSettings): vscode.TextEditorDecorationType {
29 const options: vscode.DecorationRenderOptions = {} 30 const options: vscode.DecorationRenderOptions = {};
30 options.rangeBehavior = vscode.DecorationRangeBehavior.OpenOpen 31 options.rangeBehavior = vscode.DecorationRangeBehavior.OpenOpen;
31 if (themeStyle.foreground) { 32 if (themeStyle.foreground) {
32 options.color = themeStyle.foreground 33 options.color = themeStyle.foreground;
33 } 34 }
34 if (themeStyle.background) { 35 if (themeStyle.background) {
35 options.backgroundColor = themeStyle.background 36 options.backgroundColor = themeStyle.background;
36 } 37 }
37 if (themeStyle.fontStyle) { 38 if (themeStyle.fontStyle) {
38 const parts: string[] = themeStyle.fontStyle.split(' ') 39 const parts: string[] = themeStyle.fontStyle.split(' ');
39 parts.forEach((part) => { 40 parts.forEach((part) => {
40 switch (part) { 41 switch (part) {
41 case 'italic': 42 case 'italic':
42 options.fontStyle = 'italic' 43 options.fontStyle = 'italic';
43 break 44 break;
44 case 'bold': 45 case 'bold':
45 options.fontWeight = 'bold' 46 options.fontWeight = 'bold';
46 47 break;
47 break
48 case 'underline': 48 case 'underline':
49 options.textDecoration = 'underline' 49 options.textDecoration = 'underline';
50 break 50 break;
51 default: 51 default:
52 break 52 break;
53 } 53 }
54 }) 54 })
55 } 55 }
56 return vscode.window.createTextEditorDecorationType(options) 56 return vscode.window.createTextEditorDecorationType(options);
57} 57}
58 58
59export class Highlighter { 59export class Highlighter {
@@ -66,7 +66,7 @@ export class Highlighter {
66 textDecoration?: string 66 textDecoration?: string
67 ): [string, vscode.TextEditorDecorationType] => { 67 ): [string, vscode.TextEditorDecorationType] => {
68 68
69 const rule = scopesMapper.toRule(tag, scopes.find) 69 const rule = scopesMapper.toRule(tag, scopes.find);
70 70
71 if (rule) { 71 if (rule) {
72 const decor = createDecorationFromTextmate(rule); 72 const decor = createDecorationFromTextmate(rule);