1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
import * as vscode from 'vscode'
import { TextMateRuleSettings } from './scopes'
let mappings = new Map<string, string[]>()
const defaultMapping = new Map<string, string[]>([
['comment', ['comment']],
['string', ['string']],
['keyword', ['keyword']],
['keyword.control', ['keyword.control', 'keyword', 'keyword.other']],
['keyword.unsafe', ['storage.modifier', 'keyword.other', 'keyword.control']],
['function', ['entity.name.function']],
['parameter', ['variable.parameter']],
['constant', ['constant', 'variable']],
['type', ['entity.name.type']],
['builtin', ['variable.language', 'support.type', 'support.type']],
['text', ['string', 'string.quoted', 'string.regexp']],
['attribute', ['keyword']],
['literal', ['string', 'string.quoted', 'string.regexp']],
['macro', ['support.other']],
['variable', ['variable']],
['variable.mut', ['variable']],
['field', ['variable.object.property']],
['module', ['entity.name.section']]
]
)
function find(scope: string): string[] {
return mappings.get(scope) || []
}
export function toRule(scope: string, intoRule: (scope: string) => TextMateRuleSettings | undefined): TextMateRuleSettings | undefined {
return find(scope).map(intoRule).find(rule => rule !== null)
}
export function load() {
const configuration = vscode.workspace
.getConfiguration('rust-analyzer')
.get('scopeMappings') as Map<string, string[]> | undefined || new Map()
mappings = new Map([...Array.from(defaultMapping.entries()), ...Array.from(configuration.entries())]);
}
|