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'
34import editorWorker from 'monaco-editor-core/esm/vs/editor/editor.worker?worker'
4- import vueWorker from './vue.worker?worker'
55import * as onigasm from 'onigasm'
66import 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'
98import { Store } from '../store'
109import { getOrCreateModel } from './utils'
1110import type { CreateData } from './vue.worker'
11+ import vueWorker from './vue.worker?worker'
1212
1313let initted = false
1414export 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 ) && ! / ^ \/ n o d e _ m o d u l e s / . test ( path ) ) {
50+ if ( / ^ \/ / . test ( path ) ) {
5351 const fileName = path . replace ( '/' , '' )
5452 if ( fileName !== store . state . activeFile . filename ) {
5553 store . setActive ( fileName )
0 commit comments