-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
configure-tokenizer.js
52 lines (45 loc) · 1.51 KB
/
configure-tokenizer.js
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
import { loadWASM } from 'onigasm'; // peer dependency of 'monaco-textmate'
import { Registry } from 'monaco-textmate'; // peer dependency
import { wireTmGrammars } from './set-grammars';
/* eslint-disable */
import cssGrammar from '!raw-loader!./tmGrammars/css.json.tmLanguage';
import htmlGrammar from '!raw-loader!./tmGrammars/html.json.tmLanguage';
import tsGrammar from '!raw-loader!./tmGrammars/TypeScriptReact.tmLanguage';
/* eslint-enable */
let grammarsLoaded = false;
export async function liftOff(monaco) {
if (grammarsLoaded) {
return;
}
grammarsLoaded = true;
// eslint-disable-next-line global-require
await loadWASM('/public/onigasm/2.2.1/onigasm.wasm'); // See https://www.npmjs.com/package/onigasm#light-it-up
const registry = new Registry({
getGrammarDefinition: async scopeName => {
if (scopeName === 'source.css') {
return {
format: 'json',
content: cssGrammar,
};
}
if (scopeName === 'text.html.basic') {
return {
format: 'json',
content: htmlGrammar,
};
}
return {
format: 'plist',
content: tsGrammar,
};
},
});
// map of monaco "language id's" to TextMate scopeNames
const grammars = new Map();
grammars.set('css', 'source.css');
grammars.set('html', 'text.html.basic');
grammars.set('vue', 'text.html.basic');
grammars.set('typescript', 'source.tsx');
grammars.set('javascript', 'source.js');
await wireTmGrammars(monaco, registry, grammars);
}