diff options
author | Seivan Heidari <[email protected]> | 2019-11-09 16:23:30 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-11-09 16:23:30 +0000 |
commit | 83a33fbbeae9cbec8bec855e9338b7ccd08bd3a0 (patch) | |
tree | 7378bc3b85599264027eaab28ff017ed933fb984 /editors/code/src/scopes_mapper.ts | |
parent | 529b227d42951feabf64c8c964b00e726dd92d46 (diff) |
Vscode wasn't running the linter automatically so ran `npm run fix` - wonder if it's related to `tslint` being deprecated.
Diffstat (limited to 'editors/code/src/scopes_mapper.ts')
-rw-r--r-- | editors/code/src/scopes_mapper.ts | 58 |
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 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import { TextMateRuleSettings } from './scopes'; | 2 | import { TextMateRuleSettings } from './scopes'; |
3 | 3 | ||
4 | |||
5 | |||
6 | let mappings = new Map<string, string[]>(); | 4 | let mappings = new Map<string, string[]>(); |
7 | 5 | ||
8 | |||
9 | const defaultMapping = new Map<string, string[]>([ | 6 | const 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. |
32 | export function find(scope: string): string[] { | 47 | export function find(scope: string): string[] { |
33 | return mappings.get(scope) || []; | 48 | return mappings.get(scope) || []; |
34 | } | 49 | } |
35 | 50 | ||
36 | export function toRule(scope: string, intoRule: (scope: string) => TextMateRuleSettings | undefined): TextMateRuleSettings | undefined { | 51 | export 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 | |||
41 | function isString(value: any): value is string { | 60 | function 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 | |||
50 | export function load() { | 68 | export 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 | ||