-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Monaco editor initialization and language configuration
- Loading branch information
1 parent
08d83fe
commit 0aa3c35
Showing
3 changed files
with
67 additions
and
19 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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
// @ts-ignore | ||
self.MonacoEnvironment = { | ||
getWorker: function (workerId, label) { | ||
const getWorkerModule = (moduleUrl: string, label: string) => { | ||
const workerUrl = self.MonacoEnvironment?.getWorkerUrl?.(moduleUrl, label); | ||
if (!workerUrl) { | ||
throw new Error(`Unable to get worker URL for module: ${moduleUrl} and label: ${label}`); | ||
} | ||
return new Worker(workerUrl, { | ||
name: label, | ||
type: 'module' | ||
}); | ||
}; | ||
|
||
switch (label) { | ||
case 'json': | ||
return getWorkerModule('/monaco-editor/esm/vs/language/json/json.worker?worker', label); | ||
case 'css': | ||
case 'scss': | ||
case 'less': | ||
return getWorkerModule('/monaco-editor/esm/vs/language/css/css.worker?worker', label); | ||
case 'html': | ||
case 'handlebars': | ||
case 'razor': | ||
return getWorkerModule('/monaco-editor/esm/vs/language/html/html.worker?worker', label); | ||
case 'typescript': | ||
case 'javascript': | ||
return getWorkerModule('/monaco-editor/esm/vs/language/typescript/ts.worker?worker', label); | ||
default: | ||
return getWorkerModule('/monaco-editor/esm/vs/editor/editor.worker?worker', label); | ||
} | ||
} | ||
}; | ||
|
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