From b2dd1a133a86602a2953cecf15fe77eaddf091a5 Mon Sep 17 00:00:00 2001 From: Kai Salmen Date: Thu, 7 Sep 2023 23:42:47 +0200 Subject: [PATCH 1/4] Make userConfiguration a top-level configuration item and apply semanticHighlighting.enabled' from editor options --- .../langium/config/wrapperLangiumClassic.ts | 8 ++++-- .../examples/src/langium/wrapperLangium.ts | 4 --- .../src/editorAppBase.ts | 26 ++++++++++++------- .../src/editorAppClassic.ts | 14 +++++++--- .../src/editorAppVscodeApi.ts | 12 ++------- packages/monaco-editor-wrapper/src/index.ts | 4 +-- packages/monaco-editor-wrapper/src/wrapper.ts | 15 ++++++----- 7 files changed, 47 insertions(+), 36 deletions(-) diff --git a/packages/examples/src/langium/config/wrapperLangiumClassic.ts b/packages/examples/src/langium/config/wrapperLangiumClassic.ts index 7427a55..029b085 100644 --- a/packages/examples/src/langium/config/wrapperLangiumClassic.ts +++ b/packages/examples/src/langium/config/wrapperLangiumClassic.ts @@ -31,12 +31,16 @@ export const setupLangiumClientClassic = async (): Promise => { code: code, useDiffEditor: false, editorOptions: { - 'semanticHighlighting.enabled': 'configuredByTheme' + 'semanticHighlighting.enabled': true }, languageExtensionConfig: { id: 'langium' }, languageDef: LangiumMonarchContent, themeData: LangiumTheme, - theme: 'langium-theme' + theme: 'langium-theme', + userConfiguration: { + json: '{}' + // `{ json: "editor.semanticHighlighting.enabled": true }` + } } }, languageClientConfig: { diff --git a/packages/examples/src/langium/wrapperLangium.ts b/packages/examples/src/langium/wrapperLangium.ts index e71b1ba..a4bddb0 100644 --- a/packages/examples/src/langium/wrapperLangium.ts +++ b/packages/examples/src/langium/wrapperLangium.ts @@ -4,7 +4,6 @@ * ------------------------------------------------------------------------------------------ */ import 'vscode/default-extensions/theme-defaults'; -import { updateUserConfiguration } from 'vscode/service-override/configuration'; import { buildWorkerDefinition } from 'monaco-editor-workers'; import { MonacoEditorLanguageClientWrapper } from 'monaco-editor-wrapper'; import { setupLangiumClientVscodeApi } from './config/wrapperLangiumVscode.js'; @@ -47,9 +46,6 @@ export const startLangiumClientClassic = async () => { const config = await setupLangiumClientClassic(); wrapper = new MonacoEditorLanguageClientWrapper(); await wrapper.start(config); - updateUserConfiguration(`{ - "editor.semanticHighlighting.enabled": true - }`); } catch (e) { console.log(e); } diff --git a/packages/monaco-editor-wrapper/src/editorAppBase.ts b/packages/monaco-editor-wrapper/src/editorAppBase.ts index 6fc6a56..9c1ed33 100644 --- a/packages/monaco-editor-wrapper/src/editorAppBase.ts +++ b/packages/monaco-editor-wrapper/src/editorAppBase.ts @@ -1,14 +1,11 @@ import { editor, Uri } from 'monaco-editor'; import { createConfiguredEditor, createConfiguredDiffEditor, createModelReference, ITextFileEditorModel } from 'vscode/monaco'; import { IReference } from 'vscode/service-override/editor'; +import { updateUserConfiguration } from 'vscode/service-override/configuration'; import { ModelUpdate, UserConfig, WrapperConfig } from './wrapper.js'; import { EditorAppConfigClassic } from './editorAppClassic.js'; import { EditorAppConfigVscodeApi } from './editorAppVscodeApi.js'; -export type VscodeUserConfiguration = { - json?: string; -} - export type EditorAppBaseConfig = { languageId: string; code: string; @@ -18,10 +15,15 @@ export type EditorAppBaseConfig = { codeOriginalUri?: string; domReadOnly?: boolean; readOnly?: boolean; + userConfiguration?: UserConfiguration; } export type EditorAppType = 'vscodeApi' | 'classic'; +export type UserConfiguration = { + json?: string; +} + /** * This is the base class for both Monaco Ediotor Apps: * - EditorAppClassic @@ -43,9 +45,9 @@ export abstract class EditorAppBase { this.id = id; } - protected buildConfig(userConfig: UserConfig) { + protected buildConfig(userConfig: UserConfig): EditorAppBaseConfig { const userAppConfig = userConfig.wrapperConfig.editorAppConfig; - return { + const config = { languageId: userAppConfig.languageId, code: userAppConfig.code ?? '', codeOriginal: userAppConfig.codeOriginal ?? '', @@ -54,7 +56,11 @@ export abstract class EditorAppBase { codeOriginalUri: userAppConfig.codeOriginalUri ?? undefined, readOnly: userAppConfig.readOnly ?? false, domReadOnly: userAppConfig.domReadOnly ?? false, + userConfiguration: userAppConfig.userConfiguration ?? { + json: '{}' + } }; + return config; } haveEditor() { @@ -201,14 +207,16 @@ export abstract class EditorAppBase { } } - updateMonacoEditorOptions(options: editor.IEditorOptions & editor.IGlobalEditorOptions) { - this.editor?.updateOptions(options); + async updateUserConfiguration(config: UserConfiguration) { + if (config.json) { + return updateUserConfiguration(config.json); + } + return Promise.reject(new Error('Supplied config is undefined')); } abstract getAppType(): string; abstract init(): Promise; abstract createEditors(container: HTMLElement): Promise; - abstract updateEditorOptions(options: editor.IEditorOptions & editor.IGlobalEditorOptions | VscodeUserConfiguration): void; abstract getConfig(): EditorAppConfigClassic | EditorAppConfigVscodeApi; abstract disposeApp(): void; } diff --git a/packages/monaco-editor-wrapper/src/editorAppClassic.ts b/packages/monaco-editor-wrapper/src/editorAppClassic.ts index 64a6dde..d88a169 100644 --- a/packages/monaco-editor-wrapper/src/editorAppClassic.ts +++ b/packages/monaco-editor-wrapper/src/editorAppClassic.ts @@ -56,6 +56,14 @@ export class EditorAppClassic extends EditorAppBase { this.config.languageExtensionConfig = userInput.languageExtensionConfig ?? undefined; this.config.languageDef = userInput.languageDef ?? undefined; this.config.themeData = userInput.themeData ?? undefined; + + if (userInput.editorOptions?.['semanticHighlighting.enabled'] === true) { + if (this.config.userConfiguration?.json) { + const parsedUserConfig = JSON.parse(this.config.userConfiguration.json); + parsedUserConfig['editor.semanticHighlighting.enabled'] = true; + this.config.userConfiguration.json = JSON.stringify(parsedUserConfig); + } + } } getAppType(): EditorAppType { @@ -100,12 +108,12 @@ export class EditorAppClassic extends EditorAppBase { } editor.setTheme(this.config.theme!); + await this.updateUserConfiguration(this.config.userConfiguration ?? {}); this.logger?.info('Init of MonacoConfig was completed.'); - return Promise.resolve(); } - async updateEditorOptions(options: editor.IEditorOptions & editor.IGlobalEditorOptions) { - this.updateMonacoEditorOptions(options); + updateMonacoEditorOptions(options: editor.IEditorOptions & editor.IGlobalEditorOptions) { + this.getEditor()?.updateOptions(options); } disposeApp(): void { diff --git a/packages/monaco-editor-wrapper/src/editorAppVscodeApi.ts b/packages/monaco-editor-wrapper/src/editorAppVscodeApi.ts index d5958a3..b557bfc 100644 --- a/packages/monaco-editor-wrapper/src/editorAppVscodeApi.ts +++ b/packages/monaco-editor-wrapper/src/editorAppVscodeApi.ts @@ -1,6 +1,5 @@ import type * as vscode from 'vscode'; -import { EditorAppBase, EditorAppBaseConfig, EditorAppType, VscodeUserConfiguration } from './editorAppBase.js'; -import { updateUserConfiguration } from 'vscode/service-override/configuration'; +import { EditorAppBase, EditorAppBaseConfig, EditorAppType } from './editorAppBase.js'; import { registerExtension, IExtensionManifest, ExtensionHostKind } from 'vscode/extensions'; import { UserConfig } from './wrapper.js'; import { verifyUrlorCreateDataUrl } from './utils.js'; @@ -11,7 +10,6 @@ export type EditorAppConfigVscodeApi = EditorAppBaseConfig & { $type: 'vscodeApi'; extension?: IExtensionManifest | object; extensionFilesOrContents?: Map; - userConfiguration?: VscodeUserConfiguration; }; export type RegisterExtensionResult = { @@ -76,16 +74,10 @@ export class EditorAppVscodeApi extends EditorAppBase { } } - await this.updateEditorOptions(this.config.userConfiguration ?? {}); + await this.updateUserConfiguration(this.config.userConfiguration ?? {}); this.logger?.info('Init of VscodeApiConfig was completed.'); } - async updateEditorOptions(config: VscodeUserConfiguration) { - if (config.json) { - return updateUserConfiguration(config.json); - } - } - disposeApp(): void { this.disposeEditor(); this.disposeDiffEditor(); diff --git a/packages/monaco-editor-wrapper/src/index.ts b/packages/monaco-editor-wrapper/src/index.ts index 3d8fcfb..b6d7d95 100644 --- a/packages/monaco-editor-wrapper/src/index.ts +++ b/packages/monaco-editor-wrapper/src/index.ts @@ -6,7 +6,7 @@ import { import type { EditorAppBaseConfig, EditorAppType, - VscodeUserConfiguration, + UserConfiguration, } from './editorAppBase.js'; import type { @@ -68,7 +68,7 @@ export type { EditorAppConfigVscodeApi, RegisterExtensionResult, RegisterLocalProcessExtensionResult, - VscodeUserConfiguration, + UserConfiguration, WebSocketCallOptions, LanguageClientConfigType, WebSocketConfigOptions, diff --git a/packages/monaco-editor-wrapper/src/wrapper.ts b/packages/monaco-editor-wrapper/src/wrapper.ts index 0896706..604c806 100644 --- a/packages/monaco-editor-wrapper/src/wrapper.ts +++ b/packages/monaco-editor-wrapper/src/wrapper.ts @@ -2,7 +2,7 @@ import { editor } from 'monaco-editor'; import { initServices, wasVscodeApiInitialized, InitializeServiceConfig, MonacoLanguageClient } from 'monaco-languageclient'; import { EditorAppVscodeApi, EditorAppConfigVscodeApi } from './editorAppVscodeApi.js'; import { EditorAppClassic, EditorAppConfigClassic } from './editorAppClassic.js'; -import { VscodeUserConfiguration, isVscodeApiEditorApp } from './editorAppBase.js'; +import { UserConfiguration, isVscodeApiEditorApp } from './editorAppBase.js'; import { LanguageClientConfig, LanguageClientWrapper } from './languageClientWrapper.js'; import { Logger, LoggerConfig } from './logger.js'; @@ -67,7 +67,6 @@ export class MonacoEditorLanguageClientWrapper { this.logger.debug('Init Services', this.serviceConfig.debugLogging); await initServices(this.serviceConfig); } - this.languageClientWrapper = new LanguageClientWrapper(userConfig.languageClientConfig, this.logger); } @@ -137,11 +136,15 @@ export class MonacoEditorLanguageClientWrapper { await this.editorApp?.updateDiffModel(modelUpdate); } - async updateEditorOptions(options: editor.IEditorOptions & editor.IGlobalEditorOptions | VscodeUserConfiguration): Promise { - if (this.editorApp) { - await this.editorApp.updateEditorOptions(options); + updateUserConfiguration(config: UserConfiguration) { + return this.editorApp?.updateUserConfiguration(config); + } + + async updateEditorOptions(options: editor.IEditorOptions & editor.IGlobalEditorOptions): Promise { + if (this.editorApp && this.editorApp.getAppType() === 'classic') { + await (this.editorApp as EditorAppClassic).updateMonacoEditorOptions(options); } else { - await Promise.reject('Update was called when editor wrapper was not correctly configured.'); + await Promise.reject('updateEditorOptions was called where editorApp is not of appType classic.'); } } From 36bf6306aa407f6724d12dbc898fc48040a5ee31 Mon Sep 17 00:00:00 2001 From: Kai Salmen Date: Fri, 8 Sep 2023 11:06:25 +0200 Subject: [PATCH 2/4] Added unit tests and made userConfiguration.json mandatory --- .../src/editorAppBase.ts | 2 +- .../src/editorAppClassic.ts | 3 +- .../src/editorAppVscodeApi.ts | 3 +- .../test/editorAppBase.test.ts | 29 +++++++++++++++++-- .../test/editorAppClassic.test.ts | 18 ++++++++++++ 5 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 packages/monaco-editor-wrapper/test/editorAppClassic.test.ts diff --git a/packages/monaco-editor-wrapper/src/editorAppBase.ts b/packages/monaco-editor-wrapper/src/editorAppBase.ts index 9c1ed33..e53578c 100644 --- a/packages/monaco-editor-wrapper/src/editorAppBase.ts +++ b/packages/monaco-editor-wrapper/src/editorAppBase.ts @@ -21,7 +21,7 @@ export type EditorAppBaseConfig = { export type EditorAppType = 'vscodeApi' | 'classic'; export type UserConfiguration = { - json?: string; + json: string; } /** diff --git a/packages/monaco-editor-wrapper/src/editorAppClassic.ts b/packages/monaco-editor-wrapper/src/editorAppClassic.ts index d88a169..e92c786 100644 --- a/packages/monaco-editor-wrapper/src/editorAppClassic.ts +++ b/packages/monaco-editor-wrapper/src/editorAppClassic.ts @@ -108,7 +108,8 @@ export class EditorAppClassic extends EditorAppBase { } editor.setTheme(this.config.theme!); - await this.updateUserConfiguration(this.config.userConfiguration ?? {}); + // buildConfig ensures userConfiguration is available + await this.updateUserConfiguration(this.config.userConfiguration!); this.logger?.info('Init of MonacoConfig was completed.'); } diff --git a/packages/monaco-editor-wrapper/src/editorAppVscodeApi.ts b/packages/monaco-editor-wrapper/src/editorAppVscodeApi.ts index b557bfc..6ff4b43 100644 --- a/packages/monaco-editor-wrapper/src/editorAppVscodeApi.ts +++ b/packages/monaco-editor-wrapper/src/editorAppVscodeApi.ts @@ -74,7 +74,8 @@ export class EditorAppVscodeApi extends EditorAppBase { } } - await this.updateUserConfiguration(this.config.userConfiguration ?? {}); + // buildConfig ensures userConfiguration is available + await this.updateUserConfiguration(this.config.userConfiguration!); this.logger?.info('Init of VscodeApiConfig was completed.'); } diff --git a/packages/monaco-editor-wrapper/test/editorAppBase.test.ts b/packages/monaco-editor-wrapper/test/editorAppBase.test.ts index e636750..50d3bfa 100644 --- a/packages/monaco-editor-wrapper/test/editorAppBase.test.ts +++ b/packages/monaco-editor-wrapper/test/editorAppBase.test.ts @@ -1,8 +1,8 @@ import { describe, expect, test } from 'vitest'; -import { isVscodeApiEditorApp } from 'monaco-editor-wrapper'; -import { createWrapperConfig } from './helper.js'; +import { EditorAppClassic, isVscodeApiEditorApp } from 'monaco-editor-wrapper'; +import { createBaseConfig, createWrapperConfig } from './helper.js'; -describe('Test MonacoEditorLanguageClientWrapper', () => { +describe('Test EditorAppBase', () => { test('isVscodeApiEditorApp: empty EditorAppConfigClassic', () => { const wrapperConfig = createWrapperConfig('classic'); @@ -13,4 +13,27 @@ describe('Test MonacoEditorLanguageClientWrapper', () => { const wrapperConfig = createWrapperConfig('vscodeApi'); expect(isVscodeApiEditorApp(wrapperConfig)).toBeTruthy(); }); + + test('config defaults', () => { + const config = createBaseConfig('classic'); + const app = new EditorAppClassic('config defaults', config); + expect(app.getConfig().languageId).toEqual('typescript'); + expect(app.getConfig().code).toEqual(''); + expect(app.getConfig().codeOriginal).toEqual(''); + expect(app.getConfig().useDiffEditor).toBeFalsy(); + expect(app.getConfig().codeUri).toBeUndefined(); + expect(app.getConfig().codeOriginalUri).toBeUndefined(); + expect(app.getConfig().readOnly).toBeFalsy(); + expect(app.getConfig().domReadOnly).toBeFalsy(); + expect(app.getConfig().userConfiguration?.json).toEqual('{}'); + }); + + test('config userConfiguration', () => { + const config = createBaseConfig('classic'); + config.wrapperConfig.editorAppConfig.userConfiguration = { + json: '{ "editor.semanticHighlighting.enabled": true }' + }; + const app = new EditorAppClassic('config defaults', config); + expect(app.getConfig().userConfiguration?.json).toEqual('{ "editor.semanticHighlighting.enabled": true }'); + }); }); diff --git a/packages/monaco-editor-wrapper/test/editorAppClassic.test.ts b/packages/monaco-editor-wrapper/test/editorAppClassic.test.ts new file mode 100644 index 0000000..db33625 --- /dev/null +++ b/packages/monaco-editor-wrapper/test/editorAppClassic.test.ts @@ -0,0 +1,18 @@ +import { describe, expect, test } from 'vitest'; +import { EditorAppClassic, EditorAppConfigClassic } from 'monaco-editor-wrapper'; +import { createBaseConfig } from './helper.js'; + +describe('Test EditorAppClassic', () => { + + test('editorOptions: semanticHighlighting', () => { + const config = createBaseConfig('classic'); + const configclassic = config.wrapperConfig.editorAppConfig as EditorAppConfigClassic; + expect(configclassic.$type).toEqual('classic'); + + configclassic.editorOptions = { + 'semanticHighlighting.enabled': true + }; + const app = new EditorAppClassic('config defaults', config); + expect(app.getConfig().userConfiguration?.json).toEqual('{"editor.semanticHighlighting.enabled":true}'); + }); +}); From 54311d4c4395a01851ebaa8336e5565367ec5b12 Mon Sep 17 00:00:00 2001 From: Kai Salmen Date: Fri, 8 Sep 2023 13:38:03 +0200 Subject: [PATCH 3/4] Allow all values of semanticHighlighting --- .../src/editorAppClassic.ts | 11 +++--- .../test/editorAppClassic.test.ts | 34 +++++++++++++++---- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/packages/monaco-editor-wrapper/src/editorAppClassic.ts b/packages/monaco-editor-wrapper/src/editorAppClassic.ts index e92c786..6b71fdf 100644 --- a/packages/monaco-editor-wrapper/src/editorAppClassic.ts +++ b/packages/monaco-editor-wrapper/src/editorAppClassic.ts @@ -57,12 +57,11 @@ export class EditorAppClassic extends EditorAppBase { this.config.languageDef = userInput.languageDef ?? undefined; this.config.themeData = userInput.themeData ?? undefined; - if (userInput.editorOptions?.['semanticHighlighting.enabled'] === true) { - if (this.config.userConfiguration?.json) { - const parsedUserConfig = JSON.parse(this.config.userConfiguration.json); - parsedUserConfig['editor.semanticHighlighting.enabled'] = true; - this.config.userConfiguration.json = JSON.stringify(parsedUserConfig); - } + // buildConfig ensures userConfiguration is available + if (userInput.editorOptions?.['semanticHighlighting.enabled'] !== undefined) { + const parsedUserConfig = JSON.parse(this.config.userConfiguration!.json); + parsedUserConfig['editor.semanticHighlighting.enabled'] = userInput.editorOptions?.['semanticHighlighting.enabled']; + this.config.userConfiguration!.json = JSON.stringify(parsedUserConfig); } } diff --git a/packages/monaco-editor-wrapper/test/editorAppClassic.test.ts b/packages/monaco-editor-wrapper/test/editorAppClassic.test.ts index db33625..7dac7fc 100644 --- a/packages/monaco-editor-wrapper/test/editorAppClassic.test.ts +++ b/packages/monaco-editor-wrapper/test/editorAppClassic.test.ts @@ -2,17 +2,39 @@ import { describe, expect, test } from 'vitest'; import { EditorAppClassic, EditorAppConfigClassic } from 'monaco-editor-wrapper'; import { createBaseConfig } from './helper.js'; +const buildConfig = () => { + const config = createBaseConfig('classic'); + (config.wrapperConfig.editorAppConfig as EditorAppConfigClassic).editorOptions = {}; + return config; +}; + describe('Test EditorAppClassic', () => { - test('editorOptions: semanticHighlighting', () => { - const config = createBaseConfig('classic'); + test('editorOptions: semanticHighlighting=true', () => { + const config = buildConfig(); const configclassic = config.wrapperConfig.editorAppConfig as EditorAppConfigClassic; - expect(configclassic.$type).toEqual('classic'); + configclassic.editorOptions!['semanticHighlighting.enabled'] = true; - configclassic.editorOptions = { - 'semanticHighlighting.enabled': true - }; const app = new EditorAppClassic('config defaults', config); + expect(configclassic.$type).toEqual('classic'); expect(app.getConfig().userConfiguration?.json).toEqual('{"editor.semanticHighlighting.enabled":true}'); }); + + test('editorOptions: semanticHighlighting=false', () => { + const config = buildConfig(); + const configclassic = config.wrapperConfig.editorAppConfig as EditorAppConfigClassic; + configclassic.editorOptions!['semanticHighlighting.enabled'] = false; + + const app = new EditorAppClassic('config defaults', config); + expect(app.getConfig().userConfiguration?.json).toEqual('{"editor.semanticHighlighting.enabled":false}'); + }); + + test('editorOptions: semanticHighlighting="configuredByTheme"', () => { + const config = buildConfig(); + const configclassic = config.wrapperConfig.editorAppConfig as EditorAppConfigClassic; + configclassic.editorOptions!['semanticHighlighting.enabled'] = 'configuredByTheme'; + + const app = new EditorAppClassic('config defaults', config); + expect(app.getConfig().userConfiguration?.json).toEqual('{"editor.semanticHighlighting.enabled":"configuredByTheme"}'); + }); }); From 52e9cdfe55ada0217d70fb9cf7f5d87479efb7ca Mon Sep 17 00:00:00 2001 From: Kai Salmen Date: Mon, 18 Sep 2023 21:35:20 +0200 Subject: [PATCH 4/4] Implemented review comments --- .../src/langium/config/wrapperLangiumClassic.ts | 4 +++- packages/monaco-editor-react/src/index.tsx | 15 ++++++++------- .../monaco-editor-wrapper/src/editorAppBase.ts | 7 +++---- packages/monaco-editor-wrapper/src/wrapper.ts | 8 -------- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/packages/examples/src/langium/config/wrapperLangiumClassic.ts b/packages/examples/src/langium/config/wrapperLangiumClassic.ts index 029b085..b00eec3 100644 --- a/packages/examples/src/langium/config/wrapperLangiumClassic.ts +++ b/packages/examples/src/langium/config/wrapperLangiumClassic.ts @@ -30,6 +30,7 @@ export const setupLangiumClientClassic = async (): Promise => { languageId: 'langium', code: code, useDiffEditor: false, + // configure it like this or in the userConfiguration editorOptions: { 'semanticHighlighting.enabled': true }, @@ -38,8 +39,9 @@ export const setupLangiumClientClassic = async (): Promise => { themeData: LangiumTheme, theme: 'langium-theme', userConfiguration: { - json: '{}' + // or configure the semantic highlighting like this: // `{ json: "editor.semanticHighlighting.enabled": true }` + json: '{}' } } }, diff --git a/packages/monaco-editor-react/src/index.tsx b/packages/monaco-editor-react/src/index.tsx index c050914..23dd17d 100644 --- a/packages/monaco-editor-react/src/index.tsx +++ b/packages/monaco-editor-react/src/index.tsx @@ -1,4 +1,4 @@ -import { EditorAppConfigClassic, MonacoEditorLanguageClientWrapper, UserConfig, WorkerConfigDirect, WorkerConfigOptions } from 'monaco-editor-wrapper'; +import { EditorAppClassic, EditorAppConfigClassic, MonacoEditorLanguageClientWrapper, UserConfig, WorkerConfigDirect, WorkerConfigOptions } from 'monaco-editor-wrapper'; import { IDisposable } from 'monaco-editor'; import * as vscode from 'vscode'; import React, { CSSProperties } from 'react'; @@ -73,17 +73,18 @@ export class MonacoEditorReactComp extends React.Component { } if (!restarted) { - if (userConfig.wrapperConfig.editorAppConfig.$type === 'classic') { - const options = (userConfig.wrapperConfig.editorAppConfig as EditorAppConfigClassic).editorOptions; + const appConfig = userConfig.wrapperConfig.editorAppConfig; + if (appConfig.$type === 'classic') { + const options = (appConfig as EditorAppConfigClassic).editorOptions; const prevOptions = (prevProps.userConfig.wrapperConfig.editorAppConfig as EditorAppConfigClassic).editorOptions; - if (options !== prevOptions) { - wrapper.updateEditorOptions((userConfig.wrapperConfig.editorAppConfig as EditorAppConfigClassic).editorOptions ?? {}); + if (options !== prevOptions && options !== undefined) { + (wrapper.getMonacoEditorApp() as EditorAppClassic).updateMonacoEditorOptions(options); } } - const languageId = userConfig.wrapperConfig.editorAppConfig.languageId; + const languageId = appConfig.languageId; + const code = appConfig.code; const prevLanguageId = prevProps.userConfig.wrapperConfig.editorAppConfig.languageId; - const code = userConfig.wrapperConfig.editorAppConfig.code; const prevCode = prevProps.userConfig.wrapperConfig.editorAppConfig.code; if (languageId !== prevLanguageId && code !== prevCode) { this.wrapper.updateModel({ diff --git a/packages/monaco-editor-wrapper/src/editorAppBase.ts b/packages/monaco-editor-wrapper/src/editorAppBase.ts index e53578c..611b730 100644 --- a/packages/monaco-editor-wrapper/src/editorAppBase.ts +++ b/packages/monaco-editor-wrapper/src/editorAppBase.ts @@ -1,7 +1,7 @@ import { editor, Uri } from 'monaco-editor'; import { createConfiguredEditor, createConfiguredDiffEditor, createModelReference, ITextFileEditorModel } from 'vscode/monaco'; import { IReference } from 'vscode/service-override/editor'; -import { updateUserConfiguration } from 'vscode/service-override/configuration'; +import { updateUserConfiguration as vscodeUpdateUserConfiguratio } from 'vscode/service-override/configuration'; import { ModelUpdate, UserConfig, WrapperConfig } from './wrapper.js'; import { EditorAppConfigClassic } from './editorAppClassic.js'; import { EditorAppConfigVscodeApi } from './editorAppVscodeApi.js'; @@ -47,7 +47,7 @@ export abstract class EditorAppBase { protected buildConfig(userConfig: UserConfig): EditorAppBaseConfig { const userAppConfig = userConfig.wrapperConfig.editorAppConfig; - const config = { + return { languageId: userAppConfig.languageId, code: userAppConfig.code ?? '', codeOriginal: userAppConfig.codeOriginal ?? '', @@ -60,7 +60,6 @@ export abstract class EditorAppBase { json: '{}' } }; - return config; } haveEditor() { @@ -209,7 +208,7 @@ export abstract class EditorAppBase { async updateUserConfiguration(config: UserConfiguration) { if (config.json) { - return updateUserConfiguration(config.json); + return vscodeUpdateUserConfiguratio(config.json); } return Promise.reject(new Error('Supplied config is undefined')); } diff --git a/packages/monaco-editor-wrapper/src/wrapper.ts b/packages/monaco-editor-wrapper/src/wrapper.ts index 604c806..6a85004 100644 --- a/packages/monaco-editor-wrapper/src/wrapper.ts +++ b/packages/monaco-editor-wrapper/src/wrapper.ts @@ -140,14 +140,6 @@ export class MonacoEditorLanguageClientWrapper { return this.editorApp?.updateUserConfiguration(config); } - async updateEditorOptions(options: editor.IEditorOptions & editor.IGlobalEditorOptions): Promise { - if (this.editorApp && this.editorApp.getAppType() === 'classic') { - await (this.editorApp as EditorAppClassic).updateMonacoEditorOptions(options); - } else { - await Promise.reject('updateEditorOptions was called where editorApp is not of appType classic.'); - } - } - public reportStatus() { const status: string[] = []; status.push('Wrapper status:');