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'
3
4
import editorWorker from 'monaco-editor-core/esm/vs/editor/editor.worker?worker'
4
- import vueWorker from './vue.worker?worker'
5
5
import * as onigasm from 'onigasm'
6
6
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'
9
8
import { Store } from '../store'
10
9
import { getOrCreateModel } from './utils'
11
10
import type { CreateData } from './vue.worker'
11
+ import vueWorker from './vue.worker?worker'
12
12
13
13
let initted = false
14
14
export function initMonaco ( store : Store ) {
@@ -20,36 +20,34 @@ export function initMonaco(store: Store) {
20
20
// create a model for each file in the store
21
21
for ( const filename in store . state . files ) {
22
22
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
25
24
getOrCreateModel (
26
- monaco . Uri . parse ( `file:///${ filename } ` ) ,
25
+ Uri . parse ( `file:///${ filename } ` ) ,
27
26
file . language ,
28
27
file . code
29
28
)
30
29
}
31
30
32
31
// 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 ( ) ) {
34
33
const uri = model . uri . toString ( )
35
34
if ( store . state . files [ uri . substring ( 'file:///' . length ) ] ) continue
36
- if ( uri . startsWith ( 'file:///node_modules /') ) continue
35
+ if ( uri . startsWith ( jsDelivrUriBase + ' /') ) continue
37
36
if ( uri . startsWith ( 'inmemory://' ) ) continue
38
37
39
38
model . dispose ( )
40
39
}
41
40
} )
42
41
43
42
// Support for go to definition
44
- monaco . editor . registerEditorOpener ( {
43
+ editor . registerEditorOpener ( {
45
44
openCodeEditor ( _ , resource ) {
46
- if ( resource . scheme === 'https' ) {
47
- // ignore cdn files
45
+ if ( resource . toString ( ) . startsWith ( jsDelivrUriBase + '/' ) ) {
48
46
return true
49
47
}
50
48
51
49
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 ) ) {
53
51
const fileName = path . replace ( '/' , '' )
54
52
if ( fileName !== store . state . activeFile . filename ) {
55
53
store . setActive ( fileName )
0 commit comments