New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

monaco-editor-wrapper

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

monaco-editor-wrapper - npm Package Compare versions

Comparing version

to
2.0.0-next.3

@@ -1,9 +0,9 @@

import type { DirectMonacoEditorWrapperConfig } from './monacoEditorWrapper.js';
import { DirectMonacoEditorWrapper } from './monacoEditorWrapper.js';
import type { MonacoVscodeApiWrapperConfig, VscodeUserConfiguration } from './monacoVscodeApiWrapper.js';
import { MonacoVscodeApiWrapper } from './monacoVscodeApiWrapper.js';
import type { EditorClassicConfig } from './editorClassic.js';
import { EditorClassic } from './editorClassic.js';
import type { EditorVscodeApiConfig, VscodeUserConfiguration } from './editorVscodeApi.js';
import { EditorVscodeApi } from './editorVscodeApi.js';
import type { EditorConfig, WebSocketConfigOptions, WorkerConfigOptions, LanguageClientConfig, UserConfig, MonacoEditorWrapper } from './wrapper.js';
import { MonacoEditorLanguageClientWrapper } from './wrapper.js';
export type { EditorConfig, MonacoEditorWrapper, DirectMonacoEditorWrapperConfig, MonacoVscodeApiWrapperConfig, VscodeUserConfiguration, WebSocketConfigOptions, WorkerConfigOptions, LanguageClientConfig, UserConfig };
export { MonacoEditorLanguageClientWrapper, DirectMonacoEditorWrapper, MonacoVscodeApiWrapper };
export type { EditorConfig, MonacoEditorWrapper, EditorClassicConfig, EditorVscodeApiConfig, VscodeUserConfiguration, WebSocketConfigOptions, WorkerConfigOptions, LanguageClientConfig, UserConfig };
export { MonacoEditorLanguageClientWrapper, EditorClassic, EditorVscodeApi };
//# sourceMappingURL=index.d.ts.map

@@ -1,5 +0,5 @@

import { DirectMonacoEditorWrapper } from './monacoEditorWrapper.js';
import { MonacoVscodeApiWrapper } from './monacoVscodeApiWrapper.js';
import { EditorClassic } from './editorClassic.js';
import { EditorVscodeApi } from './editorVscodeApi.js';
import { MonacoEditorLanguageClientWrapper, } from './wrapper.js';
export { MonacoEditorLanguageClientWrapper, DirectMonacoEditorWrapper, MonacoVscodeApiWrapper };
export { MonacoEditorLanguageClientWrapper, EditorClassic, EditorVscodeApi };
//# sourceMappingURL=index.js.map

@@ -1,4 +0,4 @@

export type { EditorConfig, MonacoEditorWrapper, DirectMonacoEditorWrapperConfig, MonacoVscodeApiWrapperConfig, VscodeUserConfiguration, WebSocketConfigOptions, WorkerConfigOptions, LanguageClientConfig, UserConfig } from './index.js';
export { MonacoEditorLanguageClientWrapper, DirectMonacoEditorWrapper, MonacoVscodeApiWrapper } from './index.js';
export type { EditorConfig, MonacoEditorWrapper, EditorClassicConfig, EditorVscodeApiConfig, VscodeUserConfiguration, WebSocketConfigOptions, WorkerConfigOptions, LanguageClientConfig, UserConfig } from './index.js';
export { MonacoEditorLanguageClientWrapper, EditorClassic, EditorVscodeApi } from './index.js';
import './indexLanguagesOnly.js';
//# sourceMappingURL=indexAllLanguages.d.ts.map

@@ -1,3 +0,3 @@

export { MonacoEditorLanguageClientWrapper, DirectMonacoEditorWrapper, MonacoVscodeApiWrapper } from './index.js';
export { MonacoEditorLanguageClientWrapper, EditorClassic, EditorVscodeApi } from './index.js';
import './indexLanguagesOnly.js';
//# sourceMappingURL=indexAllLanguages.js.map
import 'monaco-editor/esm/vs/editor/edcore.main.js';
import { editor } from 'monaco-editor/esm/vs/editor/editor.api.js';
import { InitializeServiceConfig, MonacoLanguageClient } from 'monaco-languageclient';
import { MonacoVscodeApiWrapper, MonacoVscodeApiWrapperConfig, VscodeUserConfiguration } from './monacoVscodeApiWrapper.js';
import { DirectMonacoEditorWrapper, DirectMonacoEditorWrapperConfig } from './monacoEditorWrapper.js';
import { EditorVscodeApi, EditorVscodeApiConfig, VscodeUserConfiguration } from './editorVscodeApi.js';
import { EditorClassic, EditorClassicConfig } from './editorClassic.js';
export type WebSocketConfigOptions = {

@@ -40,4 +40,4 @@ secured: boolean;

serviceConfig?: InitializeServiceConfig;
monacoVscodeApiConfig?: MonacoVscodeApiWrapperConfig;
monacoEditorConfig?: DirectMonacoEditorWrapperConfig;
monacoVscodeApiConfig?: EditorVscodeApiConfig;
monacoEditorConfig?: EditorClassicConfig;
};

@@ -48,15 +48,9 @@ editorConfig: EditorConfig;

export interface MonacoEditorWrapper {
init(editorConfig: EditorConfig, wrapperConfig: MonacoVscodeApiWrapperConfig | DirectMonacoEditorWrapperConfig): Promise<void>;
init(): Promise<void>;
updateConfig(options: editor.IEditorOptions & editor.IGlobalEditorOptions | VscodeUserConfiguration): void;
}
export declare class MonacoEditorLanguageClientWrapper {
private editor;
private diffEditor;
private editorOptions;
private diffEditorOptions;
private modelRef;
private modelOriginalRef;
private languageClient;
private worker;
private monacoEditorWrapper;
private editor;
private id;

@@ -66,10 +60,7 @@ private htmlElement;

private serviceConfig;
private monacoConfig;
private editorConfig;
private languageClientConfig;
private init;
start(userConfig: UserConfig): Promise<void>;
private init;
private startInternal;
isStarted(): boolean;
getMonacoEditorWrapper(): MonacoVscodeApiWrapper | DirectMonacoEditorWrapper | undefined;
getMonacoEditorWrapper(): EditorVscodeApi | EditorClassic | undefined;
getEditor(): editor.IStandaloneCodeEditor | undefined;

@@ -94,8 +85,2 @@ getDiffEditor(): editor.IStandaloneDiffEditor | undefined;

updateLayout(): void;
private disposeEditor;
private disposeDiffEditor;
private createEditor;
private updateEditorModel;
private createDiffEditor;
private updateDiffEditorModel;
private startLanguageClientConnection;

@@ -102,0 +87,0 @@ private handleLanguageClientStart;

// support all editor features
import 'monaco-editor/esm/vs/editor/edcore.main.js';
import { Uri } from 'monaco-editor/esm/vs/editor/editor.api.js';
import { createConfiguredEditor, createConfiguredDiffEditor, createModelReference } from 'vscode/monaco';
import { initServices, MonacoLanguageClient, wasVscodeApiInitialized } from 'monaco-languageclient';

@@ -10,14 +8,8 @@ import { toSocket, WebSocketMessageReader, WebSocketMessageWriter } from 'vscode-ws-jsonrpc';

import normalizeUrl from 'normalize-url';
import { MonacoVscodeApiWrapper } from './monacoVscodeApiWrapper.js';
import { DirectMonacoEditorWrapper } from './monacoEditorWrapper.js';
import { EditorVscodeApi } from './editorVscodeApi.js';
import { EditorClassic } from './editorClassic.js';
export class MonacoEditorLanguageClientWrapper {
editor;
diffEditor;
editorOptions;
diffEditorOptions;
modelRef;
modelOriginalRef;
languageClient;
worker;
monacoEditorWrapper;
editor;
id;

@@ -27,9 +19,3 @@ htmlElement;

serviceConfig;
monacoConfig;
editorConfig;
languageClientConfig;
async start(userConfig) {
this.init(userConfig);
await this.startInternal();
}
init(userConfig) {

@@ -44,14 +30,2 @@ if (userConfig.editorConfig.useDiffEditor) {

this.useVscodeConfig = userConfig.wrapperConfig.useVscodeConfig;
this.editorConfig = {
languageId: userConfig.editorConfig.languageId,
code: userConfig.editorConfig.code ?? '',
codeOriginal: userConfig.editorConfig.codeOriginal ?? '',
useDiffEditor: userConfig.editorConfig.useDiffEditor === true,
theme: userConfig.editorConfig.theme ?? 'vs-light',
automaticLayout: userConfig.editorConfig.automaticLayout ?? true,
};
this.editorOptions = userConfig.editorConfig.editorOptions ?? {};
this.editorOptions.automaticLayout = this.editorConfig.automaticLayout;
this.diffEditorOptions = userConfig.editorConfig.diffEditorOptions ?? {};
this.diffEditorOptions.automaticLayout = this.editorConfig.automaticLayout;
this.languageClientConfig = {

@@ -82,8 +56,2 @@ enabled: userConfig.languageClientConfig.enabled,

}
if (this.useVscodeConfig) {
this.monacoConfig = userConfig.wrapperConfig.monacoVscodeApiConfig ?? {};
}
else {
this.monacoConfig = userConfig.wrapperConfig.monacoEditorConfig ?? {};
}
this.serviceConfig = userConfig.wrapperConfig.serviceConfig ?? {};

@@ -100,16 +68,16 @@ // always set required services

}
async startInternal() {
console.log(`Starting monaco-editor (${this.id})`);
async start(userConfig) {
this.init(userConfig);
// Always dispose old instances before start
this.disposeEditor();
this.disposeDiffEditor();
this.monacoEditorWrapper = this.useVscodeConfig ? new MonacoVscodeApiWrapper() : new DirectMonacoEditorWrapper();
await (wasVscodeApiInitialized() ? Promise.resolve('No service init on restart') : initServices(this.serviceConfig));
await this.monacoEditorWrapper?.init(this.editorConfig, this.monacoConfig);
if (this.editorConfig.useDiffEditor) {
await this.createDiffEditor(this.htmlElement);
this.editor?.disposeEditor();
this.editor?.disposeDiffEditor();
if (this.useVscodeConfig) {
this.editor = new EditorVscodeApi(this.id, userConfig);
}
else {
await this.createEditor(this.htmlElement);
this.editor = new EditorClassic(this.id, userConfig);
}
await (wasVscodeApiInitialized() ? Promise.resolve('No service init on restart') : initServices(this.serviceConfig));
await this.editor?.init();
await this.editor.createEditors(this.htmlElement);
const lcc = this.languageClientConfig;

@@ -125,5 +93,4 @@ if (lcc.enabled) {

isStarted() {
const haveEditor = this.editor !== undefined || this.diffEditor !== undefined;
// fast-fail
if (!haveEditor) {
if (!this.editor?.haveEditor()) {
return false;

@@ -137,9 +104,9 @@ }

getMonacoEditorWrapper() {
return this.monacoEditorWrapper;
return this.editor;
}
getEditor() {
return this.editor;
return this.editor?.getEditor();
}
getDiffEditor() {
return this.diffEditor;
return this.editor?.getDiffEditor();
}

@@ -150,35 +117,16 @@ getLanguageClient() {

getModel(original) {
if (this.editorConfig.useDiffEditor) {
return ((original === true) ? this.modelOriginalRef?.object.textEditorModel : this.modelRef?.object.textEditorModel) ?? undefined;
}
else {
return this.modelRef?.object.textEditorModel ?? undefined;
}
return this.editor?.getModel(original);
}
updateModel(modelUpdate) {
if (!this.editor) {
return Promise.reject(new Error('You cannot update the editor model, because the regular editor is not configured.'));
}
this.editorConfig.languageId = modelUpdate.languageId;
this.editorConfig.code = modelUpdate.code;
return this.updateEditorModel(true);
async updateModel(modelUpdate) {
await this.editor?.updateModel(modelUpdate);
}
updateDiffModel(modelUpdate) {
if (!this.diffEditor) {
return Promise.reject(new Error('You cannot update the diff editor models, because the diffEditor is not configured.'));
}
this.editorConfig.languageId = modelUpdate.languageId;
this.editorConfig.code = modelUpdate.code;
this.editorConfig.codeOriginal = modelUpdate.codeOriginal;
return this.updateDiffEditorModel();
async updateDiffModel(modelUpdate) {
await this.editor?.updateDiffModel(modelUpdate);
}
async updateEditorOptions(options) {
if (this.monacoEditorWrapper) {
await this.monacoEditorWrapper.updateConfig(options);
if (this.useVscodeConfig) {
this.editor?.updateOptions(options);
}
if (this.editor) {
await this.editor.updateConfig(options);
}
else {
return Promise.reject('Update was called when editor wrapper was not correctly configured.');
await Promise.reject('Update was called when editor wrapper was not correctly configured.');
}

@@ -193,4 +141,4 @@ }

status.push('Wrapper status:');
status.push(`Editor: ${this.editor}`);
status.push(`DiffEditor: ${this.diffEditor}`);
status.push(`Editor: ${this.editor?.getEditor()}`);
status.push(`DiffEditor: ${this.editor?.getDiffEditor()}`);
status.push(`LanguageClient: ${this.languageClient}`);

@@ -201,7 +149,7 @@ status.push(`Worker: ${this.worker}`);

async dispose() {
this.disposeEditor();
this.disposeDiffEditor();
this.editor?.disposeEditor();
this.editor?.disposeDiffEditor();
if (this.languageClientConfig.enabled) {
await this.disposeLanguageClient();
this.monacoEditorWrapper = undefined;
this.editor = undefined;
await Promise.resolve('Monaco editor and languageclient completed disposed.');

@@ -231,62 +179,4 @@ }

updateLayout() {
if (this.editorConfig.useDiffEditor) {
this.diffEditor?.layout();
}
else {
this.editor?.layout();
}
this.editor?.updateLayout();
}
disposeEditor() {
if (this.editor) {
this.modelRef?.dispose();
this.editor.dispose();
this.editor = undefined;
}
}
disposeDiffEditor() {
if (this.diffEditor) {
this.modelRef?.dispose();
this.modelOriginalRef?.dispose();
this.diffEditor.dispose();
this.diffEditor = undefined;
}
}
async createEditor(container) {
await this.updateEditorModel(false);
this.editor = createConfiguredEditor(container, this.editorOptions);
}
async updateEditorModel(updateEditor) {
this.modelRef?.dispose();
const uri = Uri.parse(`/tmp/model${this.id}.${this.editorConfig.languageId}`);
this.modelRef = await createModelReference(uri, this.editorConfig.code);
this.modelRef.object.setLanguageId(this.editorConfig.languageId);
this.editorOptions.model = this.modelRef.object.textEditorModel;
if (updateEditor && this.editor) {
this.editor.setModel(this.editorOptions.model);
}
}
createDiffEditor(container) {
this.diffEditor = createConfiguredDiffEditor(container, this.editorConfig.diffEditorOptions);
return this.updateDiffEditorModel();
}
async updateDiffEditorModel() {
this.modelRef?.dispose();
this.modelOriginalRef?.dispose();
const uri = Uri.parse(`/tmp/model${this.id}.${this.editorConfig.languageId}`);
const uriOriginal = Uri.parse(`/tmp/modelOriginal${this.id}.${this.editorConfig.languageId}`);
const promises = [];
promises.push(createModelReference(uri, this.editorConfig.code));
promises.push(createModelReference(uriOriginal, this.editorConfig.codeOriginal));
const refs = await Promise.all(promises);
this.modelRef = refs[0];
this.modelRef.object.setLanguageId(this.editorConfig.languageId);
this.modelOriginalRef = refs[1];
this.modelOriginalRef.object.setLanguageId(this.editorConfig.languageId);
if (this.diffEditor && this.modelRef.object.textEditorModel !== null && this.modelOriginalRef.object.textEditorModel !== null) {
this.diffEditor?.setModel({
original: this.modelOriginalRef.object.textEditorModel,
modified: this.modelRef.object.textEditorModel
});
}
}
startLanguageClientConnection(languageClientConfig) {

@@ -343,3 +233,3 @@ if (this.languageClient && this.languageClient.isRunning()) {

// use a language id as a document selector
documentSelector: [this.editorConfig.languageId],
documentSelector: [this.editor.getEditorConfig().languageId],
// disable the default error handler

@@ -346,0 +236,0 @@ errorHandler: {

{
"name": "monaco-editor-wrapper",
"version": "2.0.0-next.2",
"version": "2.0.0-next.3",
"license": "MIT",

@@ -70,2 +70,3 @@ "description": "Monaco-Editor and Monaco Languageclient Wrapper",

"scripts": {
"postinstall": "monaco-treemending",
"clean": "npx shx rm -rf ./dist ./bundle ./src/generated ./resources *.tsbuildinfo",

@@ -80,16 +81,12 @@ "handle:assets": "vite-node ./build/src/buildAssets.mts",

"volta": {
"node": "18.15.0",
"npm": "9.6.3"
"node": "18.16.0",
"npm": "9.6.5"
},
"dependencies": {
"@types/css-font-loading-module": "~0.0.8",
"normalize-url": "~8.0.0"
},
"peerDependencies": {
"monaco-languageclient": "5.1.0-next.3",
"monaco-languageclient": "6.0.0-next.0",
"vscode-ws-jsonrpc": "3.0.0"
},
"devDependencies": {
"@types/glob-to-regexp": "~0.4.1"
},
"repository": {

@@ -96,0 +93,0 @@ "type": "git",

@@ -1,3 +0,1 @@

import type { } from 'css-font-loading-module';
export const getMonacoEditoCss = async () => {

@@ -4,0 +2,0 @@ const res = await fetch(new URL('../../bundle/assets/style.css', window.location.href).href);

import type {
DirectMonacoEditorWrapperConfig,
} from './monacoEditorWrapper.js';
EditorClassicConfig,
} from './editorClassic.js';
import {
DirectMonacoEditorWrapper
} from './monacoEditorWrapper.js';
EditorClassic
} from './editorClassic.js';
import type {
MonacoVscodeApiWrapperConfig,
EditorVscodeApiConfig,
VscodeUserConfiguration
} from './monacoVscodeApiWrapper.js';
} from './editorVscodeApi.js';
import {
MonacoVscodeApiWrapper
} from './monacoVscodeApiWrapper.js';
EditorVscodeApi
} from './editorVscodeApi.js';

@@ -34,4 +34,4 @@ import type {

MonacoEditorWrapper,
DirectMonacoEditorWrapperConfig,
MonacoVscodeApiWrapperConfig,
EditorClassicConfig,
EditorVscodeApiConfig,
VscodeUserConfiguration,

@@ -46,4 +46,4 @@ WebSocketConfigOptions,

MonacoEditorLanguageClientWrapper,
DirectMonacoEditorWrapper,
MonacoVscodeApiWrapper
EditorClassic,
EditorVscodeApi
};
export type {
EditorConfig,
MonacoEditorWrapper,
DirectMonacoEditorWrapperConfig,
MonacoVscodeApiWrapperConfig,
EditorClassicConfig,
EditorVscodeApiConfig,
VscodeUserConfiguration,

@@ -15,6 +15,6 @@ WebSocketConfigOptions,

MonacoEditorLanguageClientWrapper,
DirectMonacoEditorWrapper,
MonacoVscodeApiWrapper
EditorClassic,
EditorVscodeApi
} from './index.js';
import './indexLanguagesOnly.js';
// support all editor features
import 'monaco-editor/esm/vs/editor/edcore.main.js';
import { editor, Uri } from 'monaco-editor/esm/vs/editor/editor.api.js';
import { createConfiguredEditor, createConfiguredDiffEditor, createModelReference } from 'vscode/monaco';
import { editor } from 'monaco-editor/esm/vs/editor/editor.api.js';
import { InitializeServiceConfig, initServices, MonacoLanguageClient, wasVscodeApiInitialized } from 'monaco-languageclient';

@@ -10,5 +9,4 @@ import { toSocket, WebSocketMessageReader, WebSocketMessageWriter } from 'vscode-ws-jsonrpc';

import normalizeUrl from 'normalize-url';
import { MonacoVscodeApiWrapper, MonacoVscodeApiWrapperConfig, VscodeUserConfiguration } from './monacoVscodeApiWrapper.js';
import { DirectMonacoEditorWrapper, DirectMonacoEditorWrapperConfig } from './monacoEditorWrapper.js';
import { IReference, ITextFileEditorModel } from 'vscode/service-override/modelEditor';
import { EditorVscodeApi, EditorVscodeApiConfig, VscodeUserConfiguration } from './editorVscodeApi.js';
import { EditorClassic, EditorClassicConfig } from './editorClassic.js';

@@ -54,4 +52,4 @@ export type WebSocketConfigOptions = {

serviceConfig?: InitializeServiceConfig;
monacoVscodeApiConfig?: MonacoVscodeApiWrapperConfig;
monacoEditorConfig?: DirectMonacoEditorWrapperConfig;
monacoVscodeApiConfig?: EditorVscodeApiConfig;
monacoEditorConfig?: EditorClassicConfig;
},

@@ -63,3 +61,3 @@ editorConfig: EditorConfig;

export interface MonacoEditorWrapper {
init(editorConfig: EditorConfig, wrapperConfig: MonacoVscodeApiWrapperConfig | DirectMonacoEditorWrapperConfig): Promise<void>;
init(): Promise<void>;
updateConfig(options: editor.IEditorOptions & editor.IGlobalEditorOptions | VscodeUserConfiguration): void;

@@ -70,15 +68,6 @@ }

private editor: editor.IStandaloneCodeEditor | undefined;
private diffEditor: editor.IStandaloneDiffEditor | undefined;
private editorOptions: editor.IStandaloneEditorConstructionOptions;
private diffEditorOptions: editor.IStandaloneDiffEditorConstructionOptions;
private modelRef: IReference<ITextFileEditorModel> | undefined;
private modelOriginalRef: IReference<ITextFileEditorModel> | undefined;
private languageClient: MonacoLanguageClient | undefined;
private worker: Worker | undefined;
private monacoEditorWrapper: DirectMonacoEditorWrapper | MonacoVscodeApiWrapper | undefined;
private editor: EditorClassic | EditorVscodeApi | undefined;

@@ -89,11 +78,4 @@ private id: string;

private serviceConfig: InitializeServiceConfig;
private monacoConfig: MonacoVscodeApiWrapperConfig | DirectMonacoEditorWrapperConfig;
private editorConfig: EditorConfig;
private languageClientConfig: LanguageClientConfig;
async start(userConfig: UserConfig) {
this.init(userConfig);
await this.startInternal();
}
private init(userConfig: UserConfig) {

@@ -109,17 +91,3 @@ if (userConfig.editorConfig.useDiffEditor) {

this.useVscodeConfig = userConfig.wrapperConfig.useVscodeConfig;
this.editorConfig = {
languageId: userConfig.editorConfig.languageId,
code: userConfig.editorConfig.code ?? '',
codeOriginal: userConfig.editorConfig.codeOriginal ?? '',
useDiffEditor: userConfig.editorConfig.useDiffEditor === true,
theme: userConfig.editorConfig.theme ?? 'vs-light',
automaticLayout: userConfig.editorConfig.automaticLayout ?? true,
};
this.editorOptions = userConfig.editorConfig.editorOptions ?? {};
this.editorOptions.automaticLayout = this.editorConfig.automaticLayout;
this.diffEditorOptions = userConfig.editorConfig.diffEditorOptions ?? {};
this.diffEditorOptions.automaticLayout = this.editorConfig.automaticLayout;
this.languageClientConfig = {

@@ -148,8 +116,2 @@ enabled: userConfig.languageClientConfig.enabled,

if (this.useVscodeConfig) {
this.monacoConfig = userConfig.wrapperConfig.monacoVscodeApiConfig ?? {};
} else {
this.monacoConfig = userConfig.wrapperConfig.monacoEditorConfig ?? {};
}
this.serviceConfig = userConfig.wrapperConfig.serviceConfig ?? {};

@@ -168,18 +130,17 @@

private async startInternal() {
console.log(`Starting monaco-editor (${this.id})`);
async start(userConfig: UserConfig) {
this.init(userConfig);
// Always dispose old instances before start
this.disposeEditor();
this.disposeDiffEditor();
this.editor?.disposeEditor();
this.editor?.disposeDiffEditor();
this.monacoEditorWrapper = this.useVscodeConfig ? new MonacoVscodeApiWrapper() : new DirectMonacoEditorWrapper();
await (wasVscodeApiInitialized() ? Promise.resolve('No service init on restart') : initServices(this.serviceConfig));
await this.monacoEditorWrapper?.init(this.editorConfig, this.monacoConfig);
if (this.editorConfig.useDiffEditor) {
await this.createDiffEditor(this.htmlElement);
if (this.useVscodeConfig) {
this.editor = new EditorVscodeApi(this.id, userConfig);
} else {
await this.createEditor(this.htmlElement);
this.editor = new EditorClassic(this.id, userConfig);
}
await (wasVscodeApiInitialized() ? Promise.resolve('No service init on restart') : initServices(this.serviceConfig));
await this.editor?.init();
await this.editor.createEditors(this.htmlElement);

@@ -196,5 +157,4 @@ const lcc = this.languageClientConfig;

isStarted(): boolean {
const haveEditor = this.editor !== undefined || this.diffEditor !== undefined;
// fast-fail
if (!haveEditor) {
if (!this.editor?.haveEditor()) {
return false;

@@ -210,11 +170,11 @@ }

getMonacoEditorWrapper() {
return this.monacoEditorWrapper;
return this.editor;
}
getEditor(): editor.IStandaloneCodeEditor | undefined {
return this.editor;
return this.editor?.getEditor();
}
getDiffEditor(): editor.IStandaloneDiffEditor | undefined {
return this.diffEditor;
return this.editor?.getDiffEditor();
}

@@ -227,22 +187,13 @@

getModel(original?: boolean): editor.ITextModel | undefined {
if (this.editorConfig.useDiffEditor) {
return ((original === true) ? this.modelOriginalRef?.object.textEditorModel : this.modelRef?.object.textEditorModel) ?? undefined;
} else {
return this.modelRef?.object.textEditorModel ?? undefined;
}
return this.editor?.getModel(original);
}
updateModel(modelUpdate: {
async updateModel(modelUpdate: {
languageId: string;
code: string;
}): Promise<void> {
if (!this.editor) {
return Promise.reject(new Error('You cannot update the editor model, because the regular editor is not configured.'));
}
this.editorConfig.languageId = modelUpdate.languageId;
this.editorConfig.code = modelUpdate.code;
return this.updateEditorModel(true);
await this.editor?.updateModel(modelUpdate);
}
updateDiffModel(modelUpdate: {
async updateDiffModel(modelUpdate: {
languageId: string;

@@ -252,19 +203,10 @@ code: string;

}): Promise<void> {
if (!this.diffEditor) {
return Promise.reject(new Error('You cannot update the diff editor models, because the diffEditor is not configured.'));
}
this.editorConfig.languageId = modelUpdate.languageId;
this.editorConfig.code = modelUpdate.code;
this.editorConfig.codeOriginal = modelUpdate.codeOriginal;
return this.updateDiffEditorModel();
await this.editor?.updateDiffModel(modelUpdate);
}
async updateEditorOptions(options: editor.IEditorOptions & editor.IGlobalEditorOptions | VscodeUserConfiguration): Promise<void> {
if (this.monacoEditorWrapper) {
await this.monacoEditorWrapper.updateConfig(options);
if (this.useVscodeConfig) {
this.editor?.updateOptions(options as editor.IEditorOptions & editor.IGlobalEditorOptions);
}
if (this.editor) {
await this.editor.updateConfig(options);
} else {
return Promise.reject('Update was called when editor wrapper was not correctly configured.');
await Promise.reject('Update was called when editor wrapper was not correctly configured.');
}

@@ -281,4 +223,4 @@ }

status.push('Wrapper status:');
status.push(`Editor: ${this.editor}`);
status.push(`DiffEditor: ${this.diffEditor}`);
status.push(`Editor: ${this.editor?.getEditor()}`);
status.push(`DiffEditor: ${this.editor?.getDiffEditor()}`);
status.push(`LanguageClient: ${this.languageClient}`);

@@ -290,8 +232,8 @@ status.push(`Worker: ${this.worker}`);

async dispose(): Promise<void> {
this.disposeEditor();
this.disposeDiffEditor();
this.editor?.disposeEditor();
this.editor?.disposeDiffEditor();
if (this.languageClientConfig.enabled) {
await this.disposeLanguageClient();
this.monacoEditorWrapper = undefined;
this.editor = undefined;
await Promise.resolve('Monaco editor and languageclient completed disposed.');

@@ -322,73 +264,5 @@ }

updateLayout() {
if (this.editorConfig.useDiffEditor) {
this.diffEditor?.layout();
} else {
this.editor?.layout();
}
this.editor?.updateLayout();
}
private disposeEditor() {
if (this.editor) {
this.modelRef?.dispose();
this.editor.dispose();
this.editor = undefined;
}
}
private disposeDiffEditor() {
if (this.diffEditor) {
this.modelRef?.dispose();
this.modelOriginalRef?.dispose();
this.diffEditor.dispose();
this.diffEditor = undefined;
}
}
private async createEditor(container: HTMLElement): Promise<void> {
await this.updateEditorModel(false);
this.editor = createConfiguredEditor(container!, this.editorOptions);
}
private async updateEditorModel(updateEditor: boolean): Promise<void> {
this.modelRef?.dispose();
const uri = Uri.parse(`/tmp/model${this.id}.${this.editorConfig.languageId}`);
this.modelRef = await createModelReference(uri, this.editorConfig.code) as unknown as IReference<ITextFileEditorModel>;
this.modelRef.object.setLanguageId(this.editorConfig.languageId);
this.editorOptions!.model = this.modelRef.object.textEditorModel;
if (updateEditor && this.editor) {
this.editor.setModel(this.editorOptions!.model);
}
}
private createDiffEditor(container: HTMLElement) {
this.diffEditor = createConfiguredDiffEditor(container!, this.editorConfig.diffEditorOptions);
return this.updateDiffEditorModel();
}
private async updateDiffEditorModel(): Promise<void> {
this.modelRef?.dispose();
this.modelOriginalRef?.dispose();
const uri = Uri.parse(`/tmp/model${this.id}.${this.editorConfig.languageId}`);
const uriOriginal = Uri.parse(`/tmp/modelOriginal${this.id}.${this.editorConfig.languageId}`);
const promises = [];
promises.push(createModelReference(uri, this.editorConfig.code));
promises.push(createModelReference(uriOriginal, this.editorConfig.codeOriginal));
const refs = await Promise.all(promises);
this.modelRef = refs[0] as unknown as IReference<ITextFileEditorModel>;
this.modelRef.object.setLanguageId(this.editorConfig.languageId);
this.modelOriginalRef = refs[1] as unknown as IReference<ITextFileEditorModel>;
this.modelOriginalRef.object.setLanguageId(this.editorConfig.languageId);
if (this.diffEditor && this.modelRef.object.textEditorModel !== null && this.modelOriginalRef.object.textEditorModel !== null) {
this.diffEditor?.setModel({
original: this.modelOriginalRef!.object!.textEditorModel,
modified: this.modelRef!.object!.textEditorModel
});
}
}
private startLanguageClientConnection(languageClientConfig: LanguageClientConfig): Promise<string> {

@@ -450,3 +324,3 @@ if (this.languageClient && this.languageClient.isRunning()) {

// use a language id as a document selector
documentSelector: [this.editorConfig.languageId],
documentSelector: [this.editor!.getEditorConfig().languageId],
// disable the default error handler

@@ -453,0 +327,0 @@ errorHandler: {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet