diff options
Diffstat (limited to 'editors/code/src/scopes_mapper.ts')
-rw-r--r-- | editors/code/src/scopes_mapper.ts | 42 |
1 files changed, 42 insertions, 0 deletions
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 @@ | |||
1 | import * as vscode from 'vscode' | ||
2 | import { TextMateRuleSettings } from './scopes' | ||
3 | |||
4 | |||
5 | |||
6 | |||
7 | let mappings = new Map<string, string[]>() | ||
8 | |||
9 | |||
10 | const 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 | ) | ||
25 | function find(scope: string): string[] { | ||
26 | return mappings.get(scope) || [] | ||
27 | } | ||
28 | |||
29 | export function toRule(scope: string, intoRule: (scope: string) => TextMateRuleSettings | undefined): TextMateRuleSettings | undefined { | ||
30 | return find(scope).map(intoRule).find(rule => rule !== null) | ||
31 | } | ||
32 | |||
33 | |||
34 | export 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 | ||