From 3f0ee9a2130e09e3a21d700effe96deca19588f3 Mon Sep 17 00:00:00 2001 From: deuscx <1475453714@qq.com> Date: Sat, 4 Feb 2023 16:41:02 +0800 Subject: [PATCH 1/2] chore: switch monaco-editor-core to monaco-editor --- README.md | 10 +++++----- package.json | 5 ++--- pnpm-lock.yaml | 19 ++++++++----------- scripts/config.ts | 2 +- src/code2monaco.ts | 2 +- src/diagnostics.ts | 2 +- src/env.d.ts | 2 +- src/grammars/index.ts | 2 +- src/index.ts | 2 +- src/monaco.contribution.ts | 4 ++-- src/monaco2code.ts | 2 +- src/prepare.ts | 2 +- src/services.ts | 2 +- src/themes/converted.ts | 2 +- src/themes/index.ts | 2 +- src/types.ts | 2 +- src/utils.ts | 2 +- src/vue.worker.ts | 2 +- src/vueMode.ts | 2 +- src/vueWorker.ts | 2 +- src/workerManager.ts | 2 +- tests/env.ts | 2 +- tests/index.ts | 2 +- vite.config.ts | 2 +- 24 files changed, 37 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 8982501..e004120 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@ `Monaco-volar` has external dependency Onigasm (to highlight code). ```console -pnpm add monaco-volar monaco-editor-core onigasm +pnpm add monaco-volar monaco-editor onigasm # or -yarn add monaco-volar monaco-editor-core onigasm +yarn add monaco-volar monaco-editor onigasm ``` @@ -22,7 +22,7 @@ yarn add monaco-volar monaco-editor-core onigasm Import `monaco-volar` when you are using monaco. It will register vue as a language automatic. ```ts -import 'monaco-editor-core' +import 'monaco-editor' import 'monaco-volar' ``` @@ -50,7 +50,7 @@ loadOnigasm() Now we can apply grammars into monaco editor instance. ```ts -import { editor } from "monaco-editor-core"; +import { editor } from "monaco-editor"; import { loadGrammars, loadTheme } from "monaco-volar"; const theme = loadTheme() @@ -70,7 +70,7 @@ loadGrammars(editorInstance); We need to let monaco know where and how to load out worker when using Vue. ```ts -import editorWorker from "monaco-editor-core/esm/vs/editor/editor.worker?worker"; +import editorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker"; import vueWorker from "monaco-volar/vue.worker?worker"; function loadMonacoEnv() { diff --git a/package.json b/package.json index 3d163f6..ed52caf 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "@vue/runtime-dom": "^3.2.37", "@vue/shared": "^3.2.37", "esbuild": "^0.14.43", - "monaco-editor-core": "^0.33.0", "monaco-editor-textmate": "^3.0.0", "monaco-textmate": "^3.0.1", "onigasm": "^2.2.5", @@ -48,11 +47,11 @@ "vue": "^3.2.37" }, "peerDependencies": { - "monaco-editor-core": "^0.33.0", + "monaco-editor": "^0.33.0", "onigasm": "^2.2.5" }, "dependencies": { - "monaco-editor-core": "^0.33.0", + "monaco-editor": "^0.33.0", "onigasm": "^2.2.5", "typesafe-path": "^0.2.1", "vscode-uri": "^3.0.6" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 13f1e3c..1b685a3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,7 +8,7 @@ specifiers: '@vue/runtime-dom': ^3.2.37 '@vue/shared': ^3.2.37 esbuild: ^0.14.43 - monaco-editor-core: ^0.33.0 + monaco-editor: ^0.33.0 monaco-editor-textmate: ^3.0.0 monaco-textmate: ^3.0.1 onigasm: ^2.2.5 @@ -22,7 +22,7 @@ specifiers: vue: ^3.2.37 dependencies: - monaco-editor-core: 0.33.0 + monaco-editor: 0.33.0 onigasm: 2.2.5 typesafe-path: 0.2.1 vscode-uri: 3.0.6 @@ -35,7 +35,7 @@ devDependencies: '@vue/runtime-dom': 3.2.37 '@vue/shared': 3.2.37 esbuild: 0.14.43 - monaco-editor-textmate: 3.0.0_monaco-textmate@3.0.1 + monaco-editor-textmate: 3.0.0_nurowwtvogix47pnszh4m7lsnu monaco-textmate: 3.0.1_onigasm@2.2.5 path-browserify: 1.0.1 prettier: 2.6.2 @@ -846,7 +846,6 @@ packages: resolution: {integrity: sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==} dependencies: yallist: 3.1.1 - dev: false /lru-cache/6.0.0: resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==} @@ -868,19 +867,19 @@ packages: brace-expansion: 2.0.1 dev: true - /monaco-editor-core/0.33.0: - resolution: {integrity: sha512-Kzxak8jnMS8vI08DcseBuOfeQlcVPpGXO210D8M+QnaNR92s4IYzgUeiow/Hld9Gi5pGvjDbPsdUXkPewoTA5g==} - dev: false - - /monaco-editor-textmate/3.0.0_monaco-textmate@3.0.1: + /monaco-editor-textmate/3.0.0_nurowwtvogix47pnszh4m7lsnu: resolution: {integrity: sha1-qQUXOA1eUjBK73gO6+q59oerm2c=} peerDependencies: monaco-editor: 0.x.x monaco-textmate: ^3.0.0 dependencies: + monaco-editor: 0.33.0 monaco-textmate: 3.0.1_onigasm@2.2.5 dev: true + /monaco-editor/0.33.0: + resolution: {integrity: sha512-VcRWPSLIUEgQJQIE0pVT8FcGBIgFoxz7jtqctE+IiCxWugD0DwgyQBcZBhdSrdMC84eumoqMZsGl2GTreOzwqw==} + /monaco-textmate/3.0.1_onigasm@2.2.5: resolution: {integrity: sha1-ttJtJmqhLtr/cGna4NbjdHy6XNc=} peerDependencies: @@ -909,7 +908,6 @@ packages: resolution: {integrity: sha1-zE0qeaD6C2TK7B9MfqNnWFpnaJI=} dependencies: lru-cache: 5.1.1 - dev: false /path-browserify/1.0.1: resolution: {integrity: sha1-2YRUqcN1PVeQhg8W9ohnueRr4f0=} @@ -1227,7 +1225,6 @@ packages: /yallist/3.1.1: resolution: {integrity: sha1-27fa+b/YusmrRev2ArjLrQ1dCP0=} - dev: false /yallist/4.0.0: resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} diff --git a/scripts/config.ts b/scripts/config.ts index 53f05bf..a806ef5 100644 --- a/scripts/config.ts +++ b/scripts/config.ts @@ -1 +1 @@ -export const externals = ["monaco-editor-core", "onigasm"]; +export const externals = ["monaco-editor", "onigasm"]; diff --git a/src/code2monaco.ts b/src/code2monaco.ts index a461957..82c2c59 100644 --- a/src/code2monaco.ts +++ b/src/code2monaco.ts @@ -7,7 +7,7 @@ import { MarkerTag, MarkerSeverity, Position, -} from "monaco-editor-core"; +} from "monaco-editor"; import * as vscode from "vscode-languageserver-protocol"; export function asCompletionList( diff --git a/src/diagnostics.ts b/src/diagnostics.ts index a92c29e..898f3fb 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -1,4 +1,4 @@ -import { editor, IDisposable } from "monaco-editor-core"; +import { editor, IDisposable } from "monaco-editor"; import type { LanguageServiceDefaults } from "./monaco.contribution"; import { WorkerAccessor } from "./types"; import type { VueWorker } from "./vueWorker"; diff --git a/src/env.d.ts b/src/env.d.ts index 4dc90fc..e0d4dbe 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -1,6 +1,6 @@ /// -declare module "monaco-editor-core/esm/vs/editor/editor.worker" { +declare module "monaco-editor/esm/vs/editor/editor.worker" { export function initialize( callback: (ctx: any, createData: any) => any ): void; diff --git a/src/grammars/index.ts b/src/grammars/index.ts index cb24edf..296919b 100644 --- a/src/grammars/index.ts +++ b/src/grammars/index.ts @@ -1,4 +1,4 @@ -import * as monaco from 'monaco-editor-core'; +import * as monaco from 'monaco-editor'; import { wireTmGrammars } from 'monaco-editor-textmate'; import { Registry, type IGrammarDefinition } from 'monaco-textmate'; diff --git a/src/index.ts b/src/index.ts index a467dba..22cab5b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import { editor } from "monaco-editor-core"; +import { editor } from "monaco-editor"; import "./monaco.contribution"; export const loadTheme = async () => { diff --git a/src/monaco.contribution.ts b/src/monaco.contribution.ts index d5224f9..0631acc 100644 --- a/src/monaco.contribution.ts +++ b/src/monaco.contribution.ts @@ -1,5 +1,5 @@ import type * as mode from "./vueMode"; -import { Emitter, type IEvent, languages } from "monaco-editor-core"; +import { Emitter, type IEvent, languages } from "monaco-editor"; import { debounce, normalizePath } from "./utils"; import * as path from "typesafe-path"; @@ -72,7 +72,7 @@ const modeConfigurationDefault: Required = { export const vueDefaults: LanguageServiceDefaults = new LanguageServiceDefaultsImpl("vue", modeConfigurationDefault); -declare module "monaco-editor-core" { +declare module "monaco-editor" { export namespace languages { export let vue: { vueDefaults: LanguageServiceDefaults }; } diff --git a/src/monaco2code.ts b/src/monaco2code.ts index 24a011f..7a7bc3b 100644 --- a/src/monaco2code.ts +++ b/src/monaco2code.ts @@ -1,4 +1,4 @@ -import { Position, IRange, languages } from "monaco-editor-core"; +import { Position, IRange, languages } from "monaco-editor"; import * as vscode from "vscode-languageserver-protocol"; export function asPosition(position: Position): vscode.Position { diff --git a/src/prepare.ts b/src/prepare.ts index 09f0c52..cc232ba 100644 --- a/src/prepare.ts +++ b/src/prepare.ts @@ -1,4 +1,4 @@ -import { Uri, languages } from "monaco-editor-core"; +import { Uri, languages } from "monaco-editor"; import { getOrCreateModel } from "./utils"; import * as path from "typesafe-path"; diff --git a/src/services.ts b/src/services.ts index 36d6174..90c43a8 100644 --- a/src/services.ts +++ b/src/services.ts @@ -1,4 +1,4 @@ -import type { worker } from "monaco-editor-core"; +import type { worker } from "monaco-editor"; import * as ts from "typescript/lib/tsserverlibrary"; import { createLanguageService, diff --git a/src/themes/converted.ts b/src/themes/converted.ts index cb79beb..8d75435 100644 --- a/src/themes/converted.ts +++ b/src/themes/converted.ts @@ -1,4 +1,4 @@ -import type * as monaco from 'monaco-editor-core'; +import type * as monaco from 'monaco-editor'; export const theme: monaco.editor.IStandaloneThemeData = { inherit: false, diff --git a/src/themes/index.ts b/src/themes/index.ts index f8b47da..70d5355 100644 --- a/src/themes/index.ts +++ b/src/themes/index.ts @@ -1,4 +1,4 @@ -import { editor } from 'monaco-editor-core' +import { editor } from 'monaco-editor' import { theme } from './converted' export async function loadTheme() { diff --git a/src/types.ts b/src/types.ts index 3eb8b36..b63bdef 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -import type { Uri, languages } from "monaco-editor-core"; +import type { Uri, languages } from "monaco-editor"; export interface WorkerAccessor { (...more: Uri[]): Promise; diff --git a/src/utils.ts b/src/utils.ts index 8bae3ce..fce6aaa 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import { Uri, editor, IDisposable } from "monaco-editor-core"; +import { Uri, editor, IDisposable } from "monaco-editor"; import * as path from "typesafe-path"; export function debounce(fn: Function, n = 100) { diff --git a/src/vue.worker.ts b/src/vue.worker.ts index cc84677..495ca24 100644 --- a/src/vue.worker.ts +++ b/src/vue.worker.ts @@ -1,4 +1,4 @@ -import * as worker from "monaco-editor-core/esm/vs/editor/editor.worker"; +import * as worker from "monaco-editor/esm/vs/editor/editor.worker"; import { VueWorker } from "./vueWorker"; self.onmessage = () => { diff --git a/src/vueMode.ts b/src/vueMode.ts index 41ca9f1..9c036aa 100644 --- a/src/vueMode.ts +++ b/src/vueMode.ts @@ -13,7 +13,7 @@ import { languages, Range, type IDisposable, -} from "monaco-editor-core"; +} from "monaco-editor"; import { createDiagnosticsAdapter } from "./diagnostics"; import { asDisposable, disposeAll } from "./utils"; import { IVueAdaptor, WorkerAccessor } from "./types"; diff --git a/src/vueWorker.ts b/src/vueWorker.ts index cde05bf..416cf25 100644 --- a/src/vueWorker.ts +++ b/src/vueWorker.ts @@ -1,4 +1,4 @@ -import type { worker } from "monaco-editor-core"; +import type { worker } from "monaco-editor"; import { getLanguageServiceAndDocumentsService } from "./services"; import * as vscode from "vscode-languageserver-protocol"; diff --git a/src/workerManager.ts b/src/workerManager.ts index 93f1e02..350f60d 100644 --- a/src/workerManager.ts +++ b/src/workerManager.ts @@ -1,6 +1,6 @@ import { LanguageServiceDefaults } from "./monaco.contribution"; import type { ICreateData, VueWorker } from "./vueWorker"; -import { type IDisposable, Uri, editor } from "monaco-editor-core"; +import { type IDisposable, Uri, editor } from "monaco-editor"; const STOP_WHEN_IDLE_FOR = 2 * 60 * 1000; // 2min diff --git a/tests/env.ts b/tests/env.ts index 9496361..26adb07 100644 --- a/tests/env.ts +++ b/tests/env.ts @@ -1,4 +1,4 @@ -import editorWorker from "monaco-editor-core/esm/vs/editor/editor.worker?worker"; +import editorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker"; import vueWorker from "../src/vue.worker?worker"; import * as onigasm from "onigasm"; import onigasmWasm from "onigasm/lib/onigasm.wasm?url"; diff --git a/tests/index.ts b/tests/index.ts index 0c8ef99..4e73c8b 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -1,5 +1,5 @@ import { loadMonacoEnv, loadOnigasm } from "./env"; -import { editor, Uri } from "monaco-editor-core"; +import { editor, Uri } from "monaco-editor"; import { loadGrammars, loadTheme, prepareVirtualFiles } from "../src/index"; import { getOrCreateModel } from "../src/utils"; import data from "./Test.vue?raw"; diff --git a/vite.config.ts b/vite.config.ts index cf20b94..4d9697c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -7,7 +7,7 @@ export default defineConfig({ include: [ "path-browserify", "@volar/vue-language-service", - "monaco-editor-core", + "monaco-editor", ], }, resolve: { From 25e23e9a7bd1f52e5c2ec48cda3c34624f4fab9c Mon Sep 17 00:00:00 2001 From: deuscx <1475453714@qq.com> Date: Sat, 4 Feb 2023 16:42:03 +0800 Subject: [PATCH 2/2] fix: vue model create --- src/prepare.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/prepare.ts b/src/prepare.ts index cc232ba..f824dfa 100644 --- a/src/prepare.ts +++ b/src/prepare.ts @@ -18,12 +18,12 @@ export function prepareVirtualFiles() { const libDtsUrl = Uri.parse("file:///lib.d.ts"); const libPromiseUrl = Uri.parse("file:///lib.es2015.promise.d.ts"); - const libEs5Model = getOrCreateModel(libEs5Url, undefined, libEs5Content); - const libDomModel = getOrCreateModel(libDomUrl, undefined, libDomContent); - const libDtsModel = getOrCreateModel(libDtsUrl, undefined, libDtsContent); + const libEs5Model = getOrCreateModel(libEs5Url, "vue", libEs5Content); + const libDomModel = getOrCreateModel(libDomUrl, "vue", libDomContent); + const libDtsModel = getOrCreateModel(libDtsUrl, "vue", libDtsContent); const libPromiseModel = getOrCreateModel( libPromiseUrl, - undefined, + "vue", libPromiseContent ); @@ -41,25 +41,25 @@ export function prepareVirtualFiles() { "file:///node_modules/%40vue/reactivity/index.d.ts" ); - const vueModel = getOrCreateModel(vueUrl, undefined, vueContent); + const vueModel = getOrCreateModel(vueUrl, "vue", vueContent); const vueRuntimeDomModel = getOrCreateModel( vueRuntimeDomUrl, - undefined, + "vue", vueRuntimeDomContent ); const vueRuntimeCoreModel = getOrCreateModel( vueRuntimeCoreUrl, - undefined, + "vue", vueRuntimeCoreContent ); const vueSharedModel = getOrCreateModel( vueSharedUrl, - undefined, + "vue", vueSharedContent ); const vueReactivityModel = getOrCreateModel( vueReactivityUrl, - undefined, + "vue", vueReactivityContent );