aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editors/code/src/config.ts2
-rw-r--r--editors/code/src/highlighting.ts11
-rw-r--r--editors/code/src/scopes.ts18
-rw-r--r--editors/code/src/scopes_mapper.ts42
4 files changed, 60 insertions, 13 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index 9f8c810b6..a3fe39098 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -1,5 +1,6 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import * as scopes from './scopes'; 2import * as scopes from './scopes';
3import * as scopesMapper from './scopes_mapper';
3import { Server } from './server'; 4import { Server } from './server';
4 5
5const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG; 6const RA_LSP_DEBUG = process.env.__RA_LSP_SERVER_DEBUG;
@@ -49,6 +50,7 @@ export class Config {
49 50
50 Server.highlighter.removeHighlights(); 51 Server.highlighter.removeHighlights();
51 scopes.load() 52 scopes.load()
53 scopesMapper.load()
52 if (config.has('highlightingOn')) { 54 if (config.has('highlightingOn')) {
53 55
54 this.highlightingOn = config.get('highlightingOn') as boolean; 56 this.highlightingOn = config.get('highlightingOn') as boolean;
diff --git a/editors/code/src/highlighting.ts b/editors/code/src/highlighting.ts
index 4b961170b..bc19fae2f 100644
--- a/editors/code/src/highlighting.ts
+++ b/editors/code/src/highlighting.ts
@@ -2,7 +2,7 @@ import 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'
5 5import * as scopesMapper from './scopes_mapper';
6 6
7import { Server } from './server'; 7import { Server } from './server';
8 8
@@ -65,10 +65,13 @@ export class Highlighter {
65 tag: string, 65 tag: string,
66 textDecoration?: string 66 textDecoration?: string
67 ): [string, vscode.TextEditorDecorationType] => { 67 ): [string, vscode.TextEditorDecorationType] => {
68 const scope = scopes.find(tag)
69 68
70 if (scope) { 69 const foundRule = scopesMapper.toRule(tag, scopes.find) || scopes.find(tag)
71 const decor = createDecorationFromTextmate(scope); 70
71
72
73 if (foundRule) {
74 const decor = createDecorationFromTextmate(foundRule);
72 return [tag, decor]; 75 return [tag, decor];
73 } 76 }
74 else { 77 else {
diff --git a/editors/code/src/scopes.ts b/editors/code/src/scopes.ts
index c9c01ba1d..470ee716f 100644
--- a/editors/code/src/scopes.ts
+++ b/editors/code/src/scopes.ts
@@ -16,16 +16,16 @@ export interface TextMateRuleSettings {
16} 16}
17 17
18// Current theme colors 18// Current theme colors
19const colors = new Map<string, TextMateRuleSettings>() 19const rules = new Map<string, TextMateRuleSettings>()
20 20
21export function find(scope: string): TextMateRuleSettings | undefined { 21export function find(scope: string): TextMateRuleSettings | undefined {
22 return colors.get(scope) 22 return rules.get(scope)
23} 23}
24 24
25// Load all textmate scopes in the currently active theme 25// Load all textmate scopes in the currently active theme
26export function load() { 26export function load() {
27 // Remove any previous theme 27 // Remove any previous theme
28 colors.clear() 28 rules.clear()
29 // Find out current color theme 29 // Find out current color theme
30 const themeName = vscode.workspace.getConfiguration('workbench').get('colorTheme') 30 const themeName = vscode.workspace.getConfiguration('workbench').get('colorTheme')
31 31
@@ -95,21 +95,21 @@ function loadColors(textMateRules: TextMateRule[]): void {
95 for (const rule of textMateRules) { 95 for (const rule of textMateRules) {
96 96
97 if (typeof rule.scope === 'string') { 97 if (typeof rule.scope === 'string') {
98 const existingRule = colors.get(rule.scope); 98 const existingRule = rules.get(rule.scope);
99 if (existingRule) { 99 if (existingRule) {
100 colors.set(rule.scope, mergeRuleSettings(existingRule, rule.settings)) 100 rules.set(rule.scope, mergeRuleSettings(existingRule, rule.settings))
101 } 101 }
102 else { 102 else {
103 colors.set(rule.scope, rule.settings) 103 rules.set(rule.scope, rule.settings)
104 } 104 }
105 } else if (rule.scope instanceof Array) { 105 } else if (rule.scope instanceof Array) {
106 for (const scope of rule.scope) { 106 for (const scope of rule.scope) {
107 const existingRule = colors.get(scope); 107 const existingRule = rules.get(scope);
108 if (existingRule) { 108 if (existingRule) {
109 colors.set(scope, mergeRuleSettings(existingRule, rule.settings)) 109 rules.set(scope, mergeRuleSettings(existingRule, rule.settings))
110 } 110 }
111 else { 111 else {
112 colors.set(scope, rule.settings) 112 rules.set(scope, rule.settings)
113 } 113 }
114 } 114 }
115 } 115 }
diff --git a/editors/code/src/scopes_mapper.ts b/editors/code/src/scopes_mapper.ts
new file mode 100644
index 000000000..995adae2d
--- /dev/null
+++ b/editors/code/src/scopes_mapper.ts
@@ -0,0 +1,42 @@
1import * as vscode from 'vscode'
2import { TextMateRuleSettings } from './scopes'
3
4
5
6
7let mappings = new Map<string, string[]>()
8
9
10const defaultMapping = new Map<string, string[]>([
11 ['keyword.unsafe', ['storage.modifier', 'keyword.other', 'keyword.control']],
12 ['function', ['entity.name.function']],
13 ['parameter', ['variable.parameter']],
14 ['type', ['entity.name.type']],
15 ['builtin', ['variable.language', 'support.type', 'support.type']],
16 ['text', ['string', 'string.quoted', 'string.regexp']],
17 ['attribute', ['keyword']],
18 ['literal', ['string', 'string.quoted', 'string.regexp']],
19 ['macro', ['support.other']],
20 ['variable.mut', ['variable']],
21 ['field', ['variable.object.property']],
22 ['module', ['entity.name.section']]
23]
24)
25function find(scope: string): string[] {
26 return mappings.get(scope) || []
27}
28
29export function toRule(scope: string, intoRule: (scope: string) => TextMateRuleSettings | undefined): TextMateRuleSettings | undefined {
30 return find(scope).map(intoRule).find(rule => rule !== null)
31}
32
33
34export function load() {
35 const configuration = vscode.workspace
36 .getConfiguration('rust-analyzer')
37 .get('scopeMappings') as Map<string, string[]> | undefined || new Map()
38
39 mappings = new Map([...Array.from(defaultMapping.entries()), ...Array.from(configuration.entries())]);
40
41
42} \ No newline at end of file