|
1 |
| -import editorWorker from 'monaco-editor-core/esm/vs/editor/editor.worker?worker'; |
2 |
| -import vueWorker from './vue.worker?worker'; |
3 |
| -import * as onigasm from "onigasm"; |
4 |
| -import onigasmWasm from "onigasm/lib/onigasm.wasm?url"; |
5 |
| -import { editor, languages, Uri } from 'monaco-editor-core'; |
6 |
| -import * as volar from '@volar/monaco'; |
7 |
| -import { Store } from '../store'; |
8 |
| -import { createJsDelivrDtsHost } from 'volar-service-typescript'; |
9 |
| -import { getOrCreateModel } from './utils'; |
| 1 | +import editorWorker from 'monaco-editor-core/esm/vs/editor/editor.worker?worker' |
| 2 | +import vueWorker from './vue.worker?worker' |
| 3 | +import * as onigasm from 'onigasm' |
| 4 | +import onigasmWasm from 'onigasm/lib/onigasm.wasm?url' |
| 5 | +import { editor, languages, Uri } from 'monaco-editor-core' |
| 6 | +import * as volar from '@volar/monaco' |
| 7 | +import { Store } from '../store' |
| 8 | +import { createJsDelivrDtsHost } from 'volar-service-typescript' |
| 9 | +import { getOrCreateModel } from './utils' |
10 | 10 |
|
11 | 11 | export function loadWasm() {
|
12 |
| - return onigasm.loadWASM(onigasmWasm); |
| 12 | + return onigasm.loadWASM(onigasmWasm) |
13 | 13 | }
|
14 | 14 |
|
15 | 15 | export function loadMonacoEnv(store: Store) {
|
16 |
| - (self as any).MonacoEnvironment = { |
| 16 | + ;(self as any).MonacoEnvironment = { |
17 | 17 | async getWorker(_: any, label: string) {
|
18 | 18 | if (label === 'vue') {
|
19 |
| - return new vueWorker(); |
| 19 | + return new vueWorker() |
20 | 20 | }
|
21 |
| - return new editorWorker(); |
| 21 | + return new editorWorker() |
22 | 22 | },
|
23 |
| - }; |
| 23 | + } |
24 | 24 | languages.register({ id: 'vue', extensions: ['.vue'] })
|
25 | 25 | languages.register({ id: 'javascript', extensions: ['.js'] })
|
26 | 26 | languages.register({ id: 'typescript', extensions: ['.ts'] })
|
27 | 27 | languages.onLanguage('vue', async () => {
|
28 | 28 | const worker = editor.createWebWorker<any>({
|
29 | 29 | moduleId: 'vs/language/vue/vueWorker',
|
30 | 30 | label: 'vue',
|
31 |
| - host: createJsDelivrDtsHost(!store.vueVersion ? {} : { |
32 |
| - 'vue': store.vueVersion, |
33 |
| - '@vue/compiler-core': store.vueVersion, |
34 |
| - '@vue/compiler-dom': store.vueVersion, |
35 |
| - '@vue/compiler-sfc': store.vueVersion, |
36 |
| - '@vue/compiler-ssr': store.vueVersion, |
37 |
| - '@vue/reactivity': store.vueVersion, |
38 |
| - '@vue/runtime-core': store.vueVersion, |
39 |
| - '@vue/runtime-dom': store.vueVersion, |
40 |
| - '@vue/shared': store.vueVersion, |
41 |
| - }, (filename, text) => { |
42 |
| - getOrCreateModel(Uri.file(filename), undefined, text); |
43 |
| - }), |
44 |
| - }); |
45 |
| - const languageId = ['vue', 'javascript', 'typescript']; |
46 |
| - const getSyncUris = () => Object.keys(store.state.files).map(filename => Uri.parse(`file:///${filename}`)); |
47 |
| - volar.editor.activateMarkers(worker, languageId, 'vue', getSyncUris, editor); |
48 |
| - volar.editor.activateAutoInsertion(worker, languageId, getSyncUris, editor); |
49 |
| - volar.languages.registerProvides(worker, languageId, getSyncUris, languages); |
| 31 | + host: createJsDelivrDtsHost( |
| 32 | + !store.vueVersion |
| 33 | + ? {} |
| 34 | + : { |
| 35 | + vue: store.vueVersion, |
| 36 | + '@vue/compiler-core': store.vueVersion, |
| 37 | + '@vue/compiler-dom': store.vueVersion, |
| 38 | + '@vue/compiler-sfc': store.vueVersion, |
| 39 | + '@vue/compiler-ssr': store.vueVersion, |
| 40 | + '@vue/reactivity': store.vueVersion, |
| 41 | + '@vue/runtime-core': store.vueVersion, |
| 42 | + '@vue/runtime-dom': store.vueVersion, |
| 43 | + '@vue/shared': store.vueVersion, |
| 44 | + }, |
| 45 | + (filename, text) => { |
| 46 | + getOrCreateModel(Uri.file(filename), undefined, text) |
| 47 | + } |
| 48 | + ), |
| 49 | + }) |
| 50 | + const languageId = ['vue', 'javascript', 'typescript'] |
| 51 | + const getSyncUris = () => |
| 52 | + Object.keys(store.state.files).map((filename) => |
| 53 | + Uri.parse(`file:///${filename}`) |
| 54 | + ) |
| 55 | + volar.editor.activateMarkers(worker, languageId, 'vue', getSyncUris, editor) |
| 56 | + volar.editor.activateAutoInsertion(worker, languageId, getSyncUris, editor) |
| 57 | + volar.languages.registerProvides(worker, languageId, getSyncUris, languages) |
50 | 58 | })
|
51 | 59 | }
|
0 commit comments