Skip to content

Commit 3cfbb7a

Browse files
johnsoncodehksxzz
authored andcommitted
Support dependencies param
1 parent 6f06ccf commit 3cfbb7a

File tree

3 files changed

+45
-38
lines changed

3 files changed

+45
-38
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"@types/node": "^20.14.2",
8282
"@typescript-eslint/eslint-plugin": "^7.13.0",
8383
"@vitejs/plugin-vue": "^5.0.5",
84-
"@volar/monaco": "~2.4.0-alpha.3",
84+
"@volar/monaco": "~2.4.0-alpha.5",
8585
"@vue/babel-plugin-jsx": "^1.2.2",
8686
"@vue/language-service": "~2.0.24",
8787
"assert-plus": "^1.0.0",

pnpm-lock.yaml

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/monaco/vue.worker.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as worker from 'monaco-editor-core/esm/vs/editor/editor.worker'
33
import type * as monaco from 'monaco-editor-core'
44
import {
55
type LanguageServiceEnvironment,
6-
activateAutomaticTypeAcquisition,
6+
createJsDelivrNpmFileSystem,
77
createTypeScriptWorkerService,
88
} from '@volar/monaco/worker'
99
import {
@@ -37,17 +37,31 @@ self.onmessage = async (msg: MessageEvent<WorkerMessage>) => {
3737
worker.initialize(
3838
(
3939
ctx: monaco.worker.IWorkerContext<WorkerHost>,
40-
{
41-
tsconfig,
42-
// TODO
43-
dependencies,
44-
}: CreateData,
40+
{ tsconfig, dependencies }: CreateData,
4541
) => {
4642
const asFileName = (uri: URI) => uri.path
4743
const asUri = (fileName: string): URI => URI.file(fileName)
4844
const env: LanguageServiceEnvironment = {
4945
workspaceFolders: [URI.file('/')],
5046
locale,
47+
fs: createJsDelivrNpmFileSystem(
48+
(uri) => {
49+
if (uri.scheme === 'file') {
50+
if (uri.path === '/node_modules') {
51+
return ''
52+
} else if (uri.path.startsWith('/node_modules/')) {
53+
return uri.path.slice('/node_modules/'.length)
54+
}
55+
}
56+
},
57+
(pkgName) => dependencies[pkgName],
58+
(path, content) => {
59+
ctx.host.onFetchCdnFile(
60+
asUri('/node_modules/' + path).toString(),
61+
content,
62+
)
63+
},
64+
),
5165
}
5266

5367
const { options: compilerOptions } = ts.convertCompilerOptionsFromJson(
@@ -58,13 +72,6 @@ self.onmessage = async (msg: MessageEvent<WorkerMessage>) => {
5872
tsconfig.vueCompilerOptions || {},
5973
)
6074

61-
activateAutomaticTypeAcquisition(env, { asFileName }, (path, content) => {
62-
ctx.host.onFetchCdnFile(
63-
asUri('/node_modules/' + path).toString(),
64-
content,
65-
)
66-
})
67-
6875
return createTypeScriptWorkerService({
6976
typescript: ts,
7077
compilerOptions,

0 commit comments

Comments
 (0)