Skip to content

Commit 4301d86

Browse files
committed
fix: cdn file models were accidentally disposed
1 parent 01778b7 commit 4301d86

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/monaco/env.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { watchEffect } from 'vue'
2-
import * as monaco from 'monaco-editor-core'
1+
import { jsDelivrUriBase } from '@volar/cdn'
2+
import * as volar from '@volar/monaco'
3+
import { editor, languages, Uri } from 'monaco-editor-core'
34
import editorWorker from 'monaco-editor-core/esm/vs/editor/editor.worker?worker'
4-
import vueWorker from './vue.worker?worker'
55
import * as onigasm from 'onigasm'
66
import onigasmWasm from 'onigasm/lib/onigasm.wasm?url'
7-
import { editor, languages, Uri } from 'monaco-editor-core'
8-
import * as volar from '@volar/monaco'
7+
import { watchEffect } from 'vue'
98
import { Store } from '../store'
109
import { getOrCreateModel } from './utils'
1110
import type { CreateData } from './vue.worker'
11+
import vueWorker from './vue.worker?worker'
1212

1313
let initted = false
1414
export function initMonaco(store: Store) {
@@ -20,36 +20,34 @@ export function initMonaco(store: Store) {
2020
// create a model for each file in the store
2121
for (const filename in store.state.files) {
2222
const file = store.state.files[filename]
23-
if (monaco.editor.getModel(monaco.Uri.parse(`file:///${filename}`)))
24-
continue
23+
if (editor.getModel(Uri.parse(`file:///${filename}`))) continue
2524
getOrCreateModel(
26-
monaco.Uri.parse(`file:///${filename}`),
25+
Uri.parse(`file:///${filename}`),
2726
file.language,
2827
file.code
2928
)
3029
}
3130

3231
// dispose of any models that are not in the store
33-
for (const model of monaco.editor.getModels()) {
32+
for (const model of editor.getModels()) {
3433
const uri = model.uri.toString()
3534
if (store.state.files[uri.substring('file:///'.length)]) continue
36-
if (uri.startsWith('file:///node_modules/')) continue
35+
if (uri.startsWith(jsDelivrUriBase + '/')) continue
3736
if (uri.startsWith('inmemory://')) continue
3837

3938
model.dispose()
4039
}
4140
})
4241

4342
// Support for go to definition
44-
monaco.editor.registerEditorOpener({
43+
editor.registerEditorOpener({
4544
openCodeEditor(_, resource) {
46-
if (resource.scheme === 'https') {
47-
// ignore cdn files
45+
if (resource.toString().startsWith(jsDelivrUriBase + '/')) {
4846
return true
4947
}
5048

5149
const path = resource.path
52-
if (/^\//.test(path) && !/^\/node_modules/.test(path)) {
50+
if (/^\//.test(path)) {
5351
const fileName = path.replace('/', '')
5452
if (fileName !== store.state.activeFile.filename) {
5553
store.setActive(fileName)

src/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
SFCTemplateCompileOptions,
99
} from 'vue/compiler-sfc'
1010
import { OutputModes } from './output/types'
11-
import { Selection } from 'monaco-editor-core'
11+
import type { Selection } from 'monaco-editor-core'
1212

1313
const defaultMainFile = 'src/App.vue'
1414

0 commit comments

Comments
 (0)