-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea2d155
commit 7f18d84
Showing
3 changed files
with
66 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,61 @@ | ||
import { useWorkerFactory } from 'monaco-editor-wrapper/workerFactory' | ||
import { initEnhancedMonacoEnvironment } from 'monaco-languageclient/vscode/services' | ||
|
||
// import cssWorker from 'monaco-editor-wrapper/workers/module/css?worker&url' | ||
// import htmlWorker from 'monaco-editor-wrapper/workers/module/html?worker&url' | ||
// import jsonWorker from 'monaco-editor-wrapper/workers/module/json?worker&url' | ||
// import editorWorker from 'monaco-editor-wrapper/workers/module/editor?worker&url' | ||
|
||
export function buildWorkerDefinition() { | ||
useWorkerFactory({ | ||
workerOverrides: { | ||
ignoreMapping: true, | ||
workerLoaders: { | ||
editorWorkerService: () => { | ||
return new Worker( | ||
new URL('monaco-editor-wrapper/workers/module/editor', import.meta.url), | ||
{ | ||
type: 'module' | ||
} | ||
) | ||
}, | ||
javascript: () => { | ||
return new Worker(new URL('monaco-editor-wrapper/workers/module/ts', import.meta.url), { | ||
type: 'module' | ||
}) | ||
}, | ||
typescript: () => { | ||
return new Worker(new URL('monaco-editor-wrapper/workers/module/ts', import.meta.url), { | ||
type: 'module' | ||
}) | ||
}, | ||
json: () => { | ||
return new Worker(new URL('monaco-editor-wrapper/workers/module/json', import.meta.url), { | ||
type: 'module' | ||
}) | ||
}, | ||
html: () => { | ||
return new Worker(new URL('monaco-editor-wrapper/workers/module/html', import.meta.url), { | ||
type: 'module' | ||
}) | ||
}, | ||
css: () => { | ||
return new Worker(new URL('monaco-editor-wrapper/workers/module/css', import.meta.url), { | ||
type: 'module' | ||
}) | ||
}, | ||
graphql: () => { | ||
console.log('Creating graphql worker') | ||
return new Worker(new URL(`./graphql.worker.bundle.js`, import.meta.url), { | ||
name: 'graphql' | ||
}) | ||
} | ||
const envEnhanced = initEnhancedMonacoEnvironment() | ||
|
||
const getWorker = (moduleId: string, label: string) => { | ||
console.log(`getWorker: moduleId: ${moduleId} label: ${label}`) | ||
|
||
let selector = label | ||
let workerLoaders = { | ||
editorWorkerService: () => { | ||
return new Worker(new URL('monaco-editor-wrapper/workers/module/editor', import.meta.url), { | ||
type: 'module' | ||
}) | ||
}, | ||
javascript: () => { | ||
return new Worker(new URL('monaco-editor-wrapper/workers/module/ts', import.meta.url), { | ||
type: 'module' | ||
}) | ||
}, | ||
typescript: () => { | ||
return new Worker(new URL('monaco-editor-wrapper/workers/module/ts', import.meta.url), { | ||
type: 'module' | ||
}) | ||
}, | ||
json: () => { | ||
return new Worker(new URL('monaco-editor-wrapper/workers/module/json', import.meta.url), { | ||
type: 'module' | ||
}) | ||
}, | ||
html: () => { | ||
return new Worker(new URL('monaco-editor-wrapper/workers/module/html', import.meta.url), { | ||
type: 'module' | ||
}) | ||
}, | ||
css: () => { | ||
return new Worker(new URL('monaco-editor-wrapper/workers/module/css', import.meta.url), { | ||
type: 'module' | ||
}) | ||
}, | ||
graphql: () => { | ||
console.log('Creating graphql worker') | ||
return new Worker(new URL(`./graphql.worker.bundle.js`, import.meta.url), { | ||
name: 'graphql' | ||
}) | ||
} | ||
} | ||
}) | ||
const workerFunc = workerLoaders[selector] | ||
if (workerFunc !== undefined) { | ||
return workerFunc() | ||
} else { | ||
throw new Error(`Unimplemented worker ${label} (${moduleId})`) | ||
} | ||
} | ||
envEnhanced.getWorker = getWorker | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters