Skip to content

Commit

Permalink
Support dependencies param
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jun 30, 2024
1 parent 35c9246 commit 9abb642
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"@types/node": "^20.12.12",
"@typescript-eslint/eslint-plugin": "^7.10.0",
"@vitejs/plugin-vue": "^5.0.4",
"@volar/monaco": "~2.4.0-alpha.3",
"@volar/monaco": "~2.4.0-alpha.5",
"@vue/babel-plugin-jsx": "^1.2.2",
"@vue/language-service": "~2.0.24",
"assert": "^2.1.0",
Expand Down
44 changes: 22 additions & 22 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 20 additions & 13 deletions src/monaco/vue.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as worker from 'monaco-editor-core/esm/vs/editor/editor.worker'
import type * as monaco from 'monaco-editor-core'
import {
type LanguageServiceEnvironment,
activateAutomaticTypeAcquisition,
createJsDelivrNpmFileSystem,
createTypeScriptWorkerService,
} from '@volar/monaco/worker'
import {
Expand Down Expand Up @@ -37,17 +37,31 @@ self.onmessage = async (msg: MessageEvent<WorkerMessage>) => {
worker.initialize(
(
ctx: monaco.worker.IWorkerContext<WorkerHost>,
{
tsconfig,
// TODO
dependencies,
}: CreateData,
{ tsconfig, dependencies }: CreateData,
) => {
const asFileName = (uri: URI) => uri.path
const asUri = (fileName: string): URI => URI.file(fileName)
const env: LanguageServiceEnvironment = {
workspaceFolders: [URI.file('/')],
locale,
fs: createJsDelivrNpmFileSystem(
(uri) => {
if (uri.scheme === 'file') {
if (uri.path === '/node_modules') {
return ''
} else if (uri.path.startsWith('/node_modules/')) {
return uri.path.slice('/node_modules/'.length)
}
}
},
(pkgName) => dependencies[pkgName],
(path, content) => {
ctx.host.onFetchCdnFile(
asUri('/node_modules/' + path).toString(),
content,
)
},
),
}

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

activateAutomaticTypeAcquisition(env, { asFileName }, (path, content) => {
ctx.host.onFetchCdnFile(
asUri('/node_modules/' + path).toString(),
content,
)
})

return createTypeScriptWorkerService({
typescript: ts,
compilerOptions,
Expand Down

0 comments on commit 9abb642

Please sign in to comment.