diff --git a/packages/monaco-editor-wrapper/src/wrapper.ts b/packages/monaco-editor-wrapper/src/wrapper.ts index f24dd13..093ea3f 100644 --- a/packages/monaco-editor-wrapper/src/wrapper.ts +++ b/packages/monaco-editor-wrapper/src/wrapper.ts @@ -33,14 +33,27 @@ export class MonacoEditorLanguageClientWrapper { private serviceConfig: InitializeServiceConfig; private logger: Logger; - private init(userConfig: UserConfig) { + async init(userConfig: UserConfig) { if (userConfig.wrapperConfig.editorAppConfig.useDiffEditor && !userConfig.wrapperConfig.editorAppConfig.codeOriginal) { throw new Error('Use diff editor was used without a valid config.'); } + // Always dispose old instances before start + this.editorApp?.disposeApp(); this.id = userConfig.id ?? Math.floor(Math.random() * 101).toString(); this.logger = new Logger(userConfig.loggerConfig); this.serviceConfig = userConfig.wrapperConfig.serviceConfig ?? {}; + + if (userConfig.wrapperConfig.editorAppConfig.$type === 'classic') { + this.editorApp = new EditorAppClassic(this.id, userConfig, this.logger); + } else { + this.editorApp = new EditorAppExtended(this.id, userConfig, this.logger); + } + // editorApps init their own service thats why they have to be created first + await this.initServices(); + + this.languageClientWrapper = new LanguageClientWrapper(this.editorApp.getConfig().languageId, + userConfig.languageClientConfig, this.logger); } private async initServices() { @@ -68,27 +81,18 @@ export class MonacoEditorLanguageClientWrapper { } async start(userConfig: UserConfig, htmlElement: HTMLElement | null) { + await this.init(userConfig); + await this.startNoInit(htmlElement); + } + + async startNoInit(htmlElement: HTMLElement | null) { if (!htmlElement) { throw new Error('No HTMLElement provided for monaco-editor.'); } - // Always dispose old instances before start - this.editorApp?.disposeApp(); - - this.init(userConfig); - - if (userConfig.wrapperConfig.editorAppConfig.$type === 'classic') { - this.editorApp = new EditorAppClassic(this.id, userConfig, this.logger); - } else { - this.editorApp = new EditorAppExtended(this.id, userConfig, this.logger); - } - await this.initServices(); - - this.languageClientWrapper = new LanguageClientWrapper(this.editorApp.getConfig().languageId, - userConfig.languageClientConfig, this.logger); this.logger.info(`Starting monaco-editor (${this.id})`); await this.editorApp?.init(); - await this.editorApp.createEditors(htmlElement); + await this.editorApp?.createEditors(htmlElement); if (this.languageClientWrapper.haveLanguageClientConfig()) { await this.languageClientWrapper.start();