Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch monaco-editor-core to monaco-editor #16

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```

Expand All @@ -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'
```

Expand Down Expand Up @@ -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()
Expand All @@ -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() {
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
19 changes: 8 additions & 11 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion scripts/config.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const externals = ["monaco-editor-core", "onigasm"];
export const externals = ["monaco-editor", "onigasm"];
2 changes: 1 addition & 1 deletion src/code2monaco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/diagnostics.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="vite/client" />

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;
Expand Down
2 changes: 1 addition & 1 deletion src/grammars/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { editor } from "monaco-editor-core";
import { editor } from "monaco-editor";
import "./monaco.contribution";

export const loadTheme = async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/monaco.contribution.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -72,7 +72,7 @@ const modeConfigurationDefault: Required<ModeConfiguration> = {
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 };
}
Expand Down
2 changes: 1 addition & 1 deletion src/monaco2code.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions src/prepare.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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
);

Expand All @@ -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
);

Expand Down
2 changes: 1 addition & 1 deletion src/services.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/themes/converted.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/themes/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { editor } from 'monaco-editor-core'
import { editor } from 'monaco-editor'
import { theme } from './converted'

export async function loadTheme() {
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Uri, languages } from "monaco-editor-core";
import type { Uri, languages } from "monaco-editor";

export interface WorkerAccessor<T> {
(...more: Uri[]): Promise<T>;
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/vue.worker.ts
Original file line number Diff line number Diff line change
@@ -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 = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/vueMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/vueWorker.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
2 changes: 1 addition & 1 deletion src/workerManager.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/env.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion tests/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineConfig({
include: [
"path-browserify",
"@volar/vue-language-service",
"monaco-editor-core",
"monaco-editor",
],
},
resolve: {
Expand Down