aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/scopes_mapper.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/scopes_mapper.ts')
-rw-r--r--editors/code/src/scopes_mapper.ts58
1 files changed, 37 insertions, 21 deletions
diff --git a/editors/code/src/scopes_mapper.ts b/editors/code/src/scopes_mapper.ts
index dfb8bf217..85c791ff5 100644
--- a/editors/code/src/scopes_mapper.ts
+++ b/editors/code/src/scopes_mapper.ts
@@ -1,17 +1,25 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import { TextMateRuleSettings } from './scopes'; 2import { TextMateRuleSettings } from './scopes';
3 3
4
5
6let mappings = new Map<string, string[]>(); 4let mappings = new Map<string, string[]>();
7 5
8
9const defaultMapping = new Map<string, string[]>([ 6const defaultMapping = new Map<string, string[]>([
10 ['comment', ['comment', 'comment.block', 'comment.line', 'comment.block.documentation']], 7 [
8 'comment',
9 [
10 'comment',
11 'comment.block',
12 'comment.line',
13 'comment.block.documentation'
14 ]
15 ],
11 ['string', ['string']], 16 ['string', ['string']],
12 ['keyword', ['keyword']], 17 ['keyword', ['keyword']],
13 ['keyword.control', ['keyword.control', 'keyword', 'keyword.other']], 18 ['keyword.control', ['keyword.control', 'keyword', 'keyword.other']],
14 ['keyword.unsafe', ['storage.modifier', 'keyword.other', 'keyword.control', 'keyword']], 19 [
20 'keyword.unsafe',
21 ['storage.modifier', 'keyword.other', 'keyword.control', 'keyword']
22 ],
15 ['function', ['entity.name.function']], 23 ['function', ['entity.name.function']],
16 ['parameter', ['variable.parameter']], 24 ['parameter', ['variable.parameter']],
17 ['constant', ['constant', 'variable']], 25 ['constant', ['constant', 'variable']],
@@ -23,21 +31,32 @@ const defaultMapping = new Map<string, string[]>([
23 ['macro', ['support.other']], 31 ['macro', ['support.other']],
24 ['variable', ['variable']], 32 ['variable', ['variable']],
25 ['variable.mut', ['variable', 'storage.modifier']], 33 ['variable.mut', ['variable', 'storage.modifier']],
26 ['field', ['variable.object.property', 'meta.field.declaration', 'meta.definition.property', 'variable.other',]], 34 [
35 'field',
36 [
37 'variable.object.property',
38 'meta.field.declaration',
39 'meta.definition.property',
40 'variable.other'
41 ]
42 ],
27 ['module', ['entity.name.section', 'entity.other']] 43 ['module', ['entity.name.section', 'entity.other']]
28] 44]);
29);
30 45
31// Temporary exported for debugging for now. 46// Temporary exported for debugging for now.
32export function find(scope: string): string[] { 47export function find(scope: string): string[] {
33 return mappings.get(scope) || []; 48 return mappings.get(scope) || [];
34} 49}
35 50
36export function toRule(scope: string, intoRule: (scope: string) => TextMateRuleSettings | undefined): TextMateRuleSettings | undefined { 51export function toRule(
37 return find(scope).map(intoRule).filter(rule => rule !== undefined)[0]; 52 scope: string,
53 intoRule: (scope: string) => TextMateRuleSettings | undefined
54): TextMateRuleSettings | undefined {
55 return find(scope)
56 .map(intoRule)
57 .filter(rule => rule !== undefined)[0];
38} 58}
39 59
40
41function isString(value: any): value is string { 60function isString(value: any): value is string {
42 return typeof value === 'string'; 61 return typeof value === 'string';
43} 62}
@@ -46,18 +65,15 @@ function isArrayOfString(value: any): value is string[] {
46 return Array.isArray(value) && value.every(item => isString(item)); 65 return Array.isArray(value) && value.every(item => isString(item));
47} 66}
48 67
49
50export function load() { 68export function load() {
51 const rawConfig: { [key: string]: any } = vscode.workspace 69 const rawConfig: { [key: string]: any } =
52 .getConfiguration('rust-analyzer') 70 vscode.workspace
53 .get('scopeMappings') 71 .getConfiguration('rust-analyzer')
54 || {}; 72 .get('scopeMappings') || {};
55 73
56 mappings = Object 74 mappings = Object.entries(rawConfig)
57 .entries(rawConfig)
58 .filter(([_, value]) => isString(value) || isArrayOfString(value)) 75 .filter(([_, value]) => isString(value) || isArrayOfString(value))
59 .reduce((list, [key, value]: [string, string | string[]]) => { 76 .reduce((list, [key, value]: [string, string | string[]]) => {
60 return list.set(key, isString(value) ? [value] : value); 77 return list.set(key, isString(value) ? [value] : value);
61 }, defaultMapping); 78 }, defaultMapping);
62 79}
63} \ No newline at end of file