-
Notifications
You must be signed in to change notification settings - Fork 5.9k
/
Copy pathvscodeTextmate.ts
54 lines (46 loc) · 1.56 KB
/
vscodeTextmate.ts
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
49
50
51
52
53
54
import * as vscodeTextmate from "../../../../lib/vscode/node_modules/vscode-textmate";
const target = vscodeTextmate as typeof vscodeTextmate;
const ctx = (require as any).context("../../../../lib/extensions", true, /.*\.tmLanguage.json$/);
// Maps grammar scope to loaded grammar
const scopeToGrammar = {} as any;
ctx.keys().forEach((key: string) => {
const value = ctx(key);
if (value.scopeName) {
scopeToGrammar[value.scopeName] = value;
}
});
target.Registry = class Registry extends vscodeTextmate.Registry {
public constructor(opts: vscodeTextmate.RegistryOptions) {
super({
...opts,
getOnigLib: (): Promise<vscodeTextmate.IOnigLib> => {
return new Promise<vscodeTextmate.IOnigLib>((res, rej) => {
const onigasm = require("onigasm");
const wasmUrl = require("!!file-loader!onigasm/lib/onigasm.wasm");
return fetch(wasmUrl).then(resp => resp.arrayBuffer()).then(buffer => {
return onigasm.loadWASM(buffer);
}).then(() => {
res({
createOnigScanner: function (patterns) { return new onigasm.OnigScanner(patterns); },
createOnigString: function (s) { return new onigasm.OnigString(s); },
});
}).catch(reason => rej(reason));
});
},
loadGrammar: async (scopeName: string) => {
if (scopeToGrammar[scopeName]) {
return scopeToGrammar[scopeName];
}
return opts.loadGrammar(scopeName);
},
});
}
};
enum StandardTokenType {
Other = 0,
Comment = 1,
String = 2,
RegEx = 4,
}
// tslint:disable-next-line no-any to override const
(target as any).StandardTokenType = StandardTokenType;