From 1eded6d4603f09114afb861c4001d2b066246dca Mon Sep 17 00:00:00 2001 From: Kai Salmen Date: Fri, 8 Nov 2024 09:32:28 +0100 Subject: [PATCH 1/2] Remove languageId configuration ambiguity --- packages/examples/src/clangd/client/config.ts | 6 ++--- .../src/eclipse.jdt.ls/client/main.ts | 3 +-- packages/examples/src/groovy/client/main.ts | 2 +- .../examples/src/json/client/wrapperWs.ts | 2 +- .../langium-dsl/config/classicConfig.ts | 2 +- .../langium-dsl/config/extendedConfig.ts | 2 +- .../config/wrapperStatemachineConfig.ts | 2 +- .../examples/src/multi/twoLanguageClients.ts | 5 ++-- packages/examples/src/python/client/config.ts | 3 +-- packages/wrapper/src/languageClientWrapper.ts | 25 +++++++++++-------- .../test/languageClientWrapper.test.ts | 10 ++++---- 11 files changed, 31 insertions(+), 31 deletions(-) diff --git a/packages/examples/src/clangd/client/config.ts b/packages/examples/src/clangd/client/config.ts index d92d923d9..03551c161 100644 --- a/packages/examples/src/clangd/client/config.ts +++ b/packages/examples/src/clangd/client/config.ts @@ -27,12 +27,10 @@ export const createWrapperConfig = async (config: { clangdWorkerHandler: ClangdWorkerHandler, lsMessageLocalPort: MessagePort }): Promise => { - const languageId = 'cpp'; return { logLevel: LogLevel.Debug, languageClientConfigs: { LANGUAGE_ID: { - languageId: languageId, name: 'Clangd WASM Language Server', connection: { options: { @@ -46,8 +44,8 @@ export const createWrapperConfig = async (config: { timeout: 1000, keepWorker: true }, - clientOptions: { - documentSelector: [languageId], + clientOptionsOrLanguageIds: { + documentSelector: ['cpp'], workspaceFolder: { index: 0, name: 'workspace', diff --git a/packages/examples/src/eclipse.jdt.ls/client/main.ts b/packages/examples/src/eclipse.jdt.ls/client/main.ts index 7692df594..38f65081e 100644 --- a/packages/examples/src/eclipse.jdt.ls/client/main.ts +++ b/packages/examples/src/eclipse.jdt.ls/client/main.ts @@ -49,14 +49,13 @@ export const runEclipseJdtLsClient = () => { }, languageClientConfigs: { java: { - languageId: 'java', connection: { options: { $type: 'WebSocketUrl', url: 'ws://localhost:30003/jdtls' } }, - clientOptions: { + clientOptionsOrLanguageIds: { documentSelector: ['java'], workspaceFolder: { index: 0, diff --git a/packages/examples/src/groovy/client/main.ts b/packages/examples/src/groovy/client/main.ts index 4fe052b41..cc5c7a41a 100644 --- a/packages/examples/src/groovy/client/main.ts +++ b/packages/examples/src/groovy/client/main.ts @@ -45,7 +45,7 @@ const userConfig: WrapperConfig = { }, languageClientConfigs: { groovy: { - languageId: 'groovy', + clientOptionsOrLanguageIds: ['groovy'], connection: { options: { $type: 'WebSocketUrl', diff --git a/packages/examples/src/json/client/wrapperWs.ts b/packages/examples/src/json/client/wrapperWs.ts index 20cd58ea1..25800ddf6 100644 --- a/packages/examples/src/json/client/wrapperWs.ts +++ b/packages/examples/src/json/client/wrapperWs.ts @@ -48,7 +48,7 @@ export const buildJsonClientUserConfig = (params: { }, languageClientConfigs: { json: { - languageId: 'json', + clientOptionsOrLanguageIds: ['json'], connection: { options: { $type: 'WebSocketUrl', diff --git a/packages/examples/src/langium/langium-dsl/config/classicConfig.ts b/packages/examples/src/langium/langium-dsl/config/classicConfig.ts index 88e5414b6..1fcff708c 100644 --- a/packages/examples/src/langium/langium-dsl/config/classicConfig.ts +++ b/packages/examples/src/langium/langium-dsl/config/classicConfig.ts @@ -51,7 +51,7 @@ export const setupLangiumClientClassic = async (): Promise => { }, languageClientConfigs: { langium: { - languageId: 'langium', + clientOptionsOrLanguageIds: ['langium'], connection: { options: { $type: 'WorkerDirect', diff --git a/packages/examples/src/langium/langium-dsl/config/extendedConfig.ts b/packages/examples/src/langium/langium-dsl/config/extendedConfig.ts index da237ff5f..536e72ccb 100644 --- a/packages/examples/src/langium/langium-dsl/config/extendedConfig.ts +++ b/packages/examples/src/langium/langium-dsl/config/extendedConfig.ts @@ -79,7 +79,7 @@ export const setupLangiumClientExtended = async (): Promise => { }, languageClientConfigs: { langium: { - languageId: 'langium', + clientOptionsOrLanguageIds: ['langium'], connection: { options: { $type: 'WorkerDirect', diff --git a/packages/examples/src/langium/statemachine/config/wrapperStatemachineConfig.ts b/packages/examples/src/langium/statemachine/config/wrapperStatemachineConfig.ts index 2c60278d3..f4613d2c9 100644 --- a/packages/examples/src/langium/statemachine/config/wrapperStatemachineConfig.ts +++ b/packages/examples/src/langium/statemachine/config/wrapperStatemachineConfig.ts @@ -38,7 +38,7 @@ export const createLangiumGlobalConfig = async (params: { const languageClientConfigs: Record | undefined = params.useLanguageClient && params.worker ? { statemachine: { - languageId: 'statemachine', + clientOptionsOrLanguageIds: ['statemachine'], connection: { options: { $type: 'WorkerDirect', diff --git a/packages/examples/src/multi/twoLanguageClients.ts b/packages/examples/src/multi/twoLanguageClients.ts index fa5837dc0..758700acf 100644 --- a/packages/examples/src/multi/twoLanguageClients.ts +++ b/packages/examples/src/multi/twoLanguageClients.ts @@ -59,7 +59,7 @@ print("Hello Moon!") }, languageClientConfigs: { json: { - languageId: 'json', + clientOptionsOrLanguageIds: ['json'], name: 'JSON Client', connection: { options: { @@ -72,7 +72,6 @@ print("Hello Moon!") } }, python: { - languageId: 'python', name: 'Python Client', connection: { options: { @@ -98,7 +97,7 @@ print("Hello Moon!") } } }, - clientOptions: { + clientOptionsOrLanguageIds: { documentSelector: ['python', 'py'], workspaceFolder: { index: 0, diff --git a/packages/examples/src/python/client/config.ts b/packages/examples/src/python/client/config.ts index 8c7a54301..215e0d7f8 100644 --- a/packages/examples/src/python/client/config.ts +++ b/packages/examples/src/python/client/config.ts @@ -31,7 +31,6 @@ export const createUserConfig = (workspaceRoot: string, code: string, codeUri: s return { languageClientConfigs: { python: { - languageId: 'python', name: 'Python Language Server Example', connection: { options: { @@ -52,7 +51,7 @@ export const createUserConfig = (workspaceRoot: string, code: string, codeUri: s }, messageTransports: { reader, writer } }, - clientOptions: { + clientOptionsOrLanguageIds: { documentSelector: ['python'], workspaceFolder: { index: 0, diff --git a/packages/wrapper/src/languageClientWrapper.ts b/packages/wrapper/src/languageClientWrapper.ts index 3dc83c9c3..9117a8a04 100644 --- a/packages/wrapper/src/languageClientWrapper.ts +++ b/packages/wrapper/src/languageClientWrapper.ts @@ -16,9 +16,8 @@ export interface ConnectionConfig { export interface LanguageClientConfig { name?: string; - languageId: string; connection: ConnectionConfig; - clientOptions?: LanguageClientOptions; + clientOptionsOrLanguageIds: LanguageClientOptions | string[]; restartOptions?: LanguageClientRestartOptions; } @@ -37,7 +36,6 @@ export class LanguageClientWrapper { private languageClient?: MonacoLanguageClient; private languageClientConfig: LanguageClientConfig; - private languageId: string; private worker?: Worker; private port?: MessagePort; private name?: string; @@ -50,7 +48,6 @@ export class LanguageClientWrapper { this.languageClientConfig = config.languageClientConfig; this.name = this.languageClientConfig.name ?? 'unnamed'; this.logger = config.logger; - this.languageId = this.languageClientConfig.languageId; } haveLanguageClient(): boolean { @@ -175,20 +172,28 @@ export class LanguageClientWrapper { this.logger?.info('performLanguageClientStart: monaco-languageclient already running!'); resolve(); } + const mlcConfig = { name: this.languageClientConfig.name ?? 'Monaco Wrapper Language Client', + clientOptions: { + }, + messageTransports + }; - // allow to fully override the clientOptions - clientOptions: this.languageClientConfig.clientOptions ?? { - documentSelector: [this.languageId], + // allow to fully override the clientOptions or just use an array of languageIds as preset + const clientOptions = this.languageClientConfig.clientOptionsOrLanguageIds; + if (Array.isArray(clientOptions)) { + mlcConfig.clientOptions = { + documentSelector: clientOptions, // disable the default error handler errorHandler: { error: () => ({ action: ErrorAction.Continue }), closed: () => ({ action: CloseAction.DoNotRestart }) } - }, - messageTransports - }; + }; + } else { + mlcConfig.clientOptions = clientOptions; + } this.languageClient = new MonacoLanguageClient(mlcConfig); diff --git a/packages/wrapper/test/languageClientWrapper.test.ts b/packages/wrapper/test/languageClientWrapper.test.ts index f0efdd6eb..d9a6b7367 100644 --- a/packages/wrapper/test/languageClientWrapper.test.ts +++ b/packages/wrapper/test/languageClientWrapper.test.ts @@ -24,7 +24,7 @@ describe('Test LanguageClientWrapper', () => { name: 'Langium LS', }); const languageClientConfig: LanguageClientConfig = { - languageId: 'javascript', + clientOptionsOrLanguageIds: ['javascript'], connection: { options: { $type: 'WorkerDirect', @@ -51,7 +51,7 @@ describe('Test LanguageClientWrapper', () => { const config = createWrapperConfigExtendedApp(); config.languageClientConfigs = { javascript: { - languageId: 'javascript', + clientOptionsOrLanguageIds: ['javascript'], connection: { options: { $type: 'WorkerDirect', @@ -84,7 +84,7 @@ describe('Test LanguageClientWrapper', () => { const config = createWrapperConfigExtendedApp(); config.languageClientConfigs = { javascript: { - languageId: 'javascript', + clientOptionsOrLanguageIds: ['javascript'], connection: { options: { $type: 'WebSocketUrl', @@ -104,7 +104,7 @@ describe('Test LanguageClientWrapper', () => { const config = createWrapperConfigExtendedApp(); config.languageClientConfigs = { javascript: { - languageId: 'javascript', + clientOptionsOrLanguageIds: ['javascript'], name: 'test-unreachable', connection: { options: { @@ -141,7 +141,7 @@ describe('Test LanguageClientWrapper', () => { const config = createWrapperConfigExtendedApp(); config.languageClientConfigs = { javascript: { - languageId: 'javascript', + clientOptionsOrLanguageIds: ['javascript'], connection: { options: { $type: 'WorkerConfig', From 1f54a53431a2b7e0d53e40949ebeb14045cc82a5 Mon Sep 17 00:00:00 2001 From: Kai Salmen Date: Fri, 8 Nov 2024 10:35:56 +0100 Subject: [PATCH 2/2] Implement review comments: Only advanced options with default errorHandler --- packages/examples/src/clangd/client/config.ts | 2 +- .../src/eclipse.jdt.ls/client/main.ts | 2 +- packages/examples/src/groovy/client/main.ts | 4 ++- .../examples/src/json/client/wrapperWs.ts | 4 ++- .../langium-dsl/config/classicConfig.ts | 4 ++- .../langium-dsl/config/extendedConfig.ts | 4 ++- .../config/wrapperStatemachineConfig.ts | 4 ++- .../examples/src/multi/twoLanguageClients.ts | 6 +++-- packages/examples/src/python/client/config.ts | 2 +- packages/wrapper/src/languageClientWrapper.ts | 25 ++++++------------- .../test/languageClientWrapper.test.ts | 20 +++++++++++---- 11 files changed, 45 insertions(+), 32 deletions(-) diff --git a/packages/examples/src/clangd/client/config.ts b/packages/examples/src/clangd/client/config.ts index 03551c161..5249b4e00 100644 --- a/packages/examples/src/clangd/client/config.ts +++ b/packages/examples/src/clangd/client/config.ts @@ -44,7 +44,7 @@ export const createWrapperConfig = async (config: { timeout: 1000, keepWorker: true }, - clientOptionsOrLanguageIds: { + clientOptions: { documentSelector: ['cpp'], workspaceFolder: { index: 0, diff --git a/packages/examples/src/eclipse.jdt.ls/client/main.ts b/packages/examples/src/eclipse.jdt.ls/client/main.ts index 38f65081e..6ea4a11ee 100644 --- a/packages/examples/src/eclipse.jdt.ls/client/main.ts +++ b/packages/examples/src/eclipse.jdt.ls/client/main.ts @@ -55,7 +55,7 @@ export const runEclipseJdtLsClient = () => { url: 'ws://localhost:30003/jdtls' } }, - clientOptionsOrLanguageIds: { + clientOptions: { documentSelector: ['java'], workspaceFolder: { index: 0, diff --git a/packages/examples/src/groovy/client/main.ts b/packages/examples/src/groovy/client/main.ts index cc5c7a41a..67e5370c8 100644 --- a/packages/examples/src/groovy/client/main.ts +++ b/packages/examples/src/groovy/client/main.ts @@ -45,7 +45,9 @@ const userConfig: WrapperConfig = { }, languageClientConfigs: { groovy: { - clientOptionsOrLanguageIds: ['groovy'], + clientOptions: { + documentSelector: ['groovy'] + }, connection: { options: { $type: 'WebSocketUrl', diff --git a/packages/examples/src/json/client/wrapperWs.ts b/packages/examples/src/json/client/wrapperWs.ts index 25800ddf6..d57bdaf11 100644 --- a/packages/examples/src/json/client/wrapperWs.ts +++ b/packages/examples/src/json/client/wrapperWs.ts @@ -48,7 +48,9 @@ export const buildJsonClientUserConfig = (params: { }, languageClientConfigs: { json: { - clientOptionsOrLanguageIds: ['json'], + clientOptions: { + documentSelector: ['json'] + }, connection: { options: { $type: 'WebSocketUrl', diff --git a/packages/examples/src/langium/langium-dsl/config/classicConfig.ts b/packages/examples/src/langium/langium-dsl/config/classicConfig.ts index 1fcff708c..e7927fac2 100644 --- a/packages/examples/src/langium/langium-dsl/config/classicConfig.ts +++ b/packages/examples/src/langium/langium-dsl/config/classicConfig.ts @@ -51,7 +51,9 @@ export const setupLangiumClientClassic = async (): Promise => { }, languageClientConfigs: { langium: { - clientOptionsOrLanguageIds: ['langium'], + clientOptions: { + documentSelector: ['langium'] + }, connection: { options: { $type: 'WorkerDirect', diff --git a/packages/examples/src/langium/langium-dsl/config/extendedConfig.ts b/packages/examples/src/langium/langium-dsl/config/extendedConfig.ts index 536e72ccb..b3c5335ef 100644 --- a/packages/examples/src/langium/langium-dsl/config/extendedConfig.ts +++ b/packages/examples/src/langium/langium-dsl/config/extendedConfig.ts @@ -79,7 +79,9 @@ export const setupLangiumClientExtended = async (): Promise => { }, languageClientConfigs: { langium: { - clientOptionsOrLanguageIds: ['langium'], + clientOptions: { + documentSelector: ['langium'] + }, connection: { options: { $type: 'WorkerDirect', diff --git a/packages/examples/src/langium/statemachine/config/wrapperStatemachineConfig.ts b/packages/examples/src/langium/statemachine/config/wrapperStatemachineConfig.ts index f4613d2c9..974080684 100644 --- a/packages/examples/src/langium/statemachine/config/wrapperStatemachineConfig.ts +++ b/packages/examples/src/langium/statemachine/config/wrapperStatemachineConfig.ts @@ -38,7 +38,9 @@ export const createLangiumGlobalConfig = async (params: { const languageClientConfigs: Record | undefined = params.useLanguageClient && params.worker ? { statemachine: { - clientOptionsOrLanguageIds: ['statemachine'], + clientOptions: { + documentSelector: ['statemachine'] + }, connection: { options: { $type: 'WorkerDirect', diff --git a/packages/examples/src/multi/twoLanguageClients.ts b/packages/examples/src/multi/twoLanguageClients.ts index 758700acf..670d29dee 100644 --- a/packages/examples/src/multi/twoLanguageClients.ts +++ b/packages/examples/src/multi/twoLanguageClients.ts @@ -59,7 +59,9 @@ print("Hello Moon!") }, languageClientConfigs: { json: { - clientOptionsOrLanguageIds: ['json'], + clientOptions: { + documentSelector: ['json'] + }, name: 'JSON Client', connection: { options: { @@ -97,7 +99,7 @@ print("Hello Moon!") } } }, - clientOptionsOrLanguageIds: { + clientOptions: { documentSelector: ['python', 'py'], workspaceFolder: { index: 0, diff --git a/packages/examples/src/python/client/config.ts b/packages/examples/src/python/client/config.ts index 215e0d7f8..224f0a64c 100644 --- a/packages/examples/src/python/client/config.ts +++ b/packages/examples/src/python/client/config.ts @@ -51,7 +51,7 @@ export const createUserConfig = (workspaceRoot: string, code: string, codeUri: s }, messageTransports: { reader, writer } }, - clientOptionsOrLanguageIds: { + clientOptions: { documentSelector: ['python'], workspaceFolder: { index: 0, diff --git a/packages/wrapper/src/languageClientWrapper.ts b/packages/wrapper/src/languageClientWrapper.ts index 9117a8a04..a35bbd4a9 100644 --- a/packages/wrapper/src/languageClientWrapper.ts +++ b/packages/wrapper/src/languageClientWrapper.ts @@ -17,7 +17,7 @@ export interface ConnectionConfig { export interface LanguageClientConfig { name?: string; connection: ConnectionConfig; - clientOptionsOrLanguageIds: LanguageClientOptions | string[]; + clientOptions: LanguageClientOptions; restartOptions?: LanguageClientRestartOptions; } @@ -176,25 +176,16 @@ export class LanguageClientWrapper { const mlcConfig = { name: this.languageClientConfig.name ?? 'Monaco Wrapper Language Client', clientOptions: { - }, - messageTransports - }; - - // allow to fully override the clientOptions or just use an array of languageIds as preset - const clientOptions = this.languageClientConfig.clientOptionsOrLanguageIds; - if (Array.isArray(clientOptions)) { - mlcConfig.clientOptions = { - documentSelector: clientOptions, - // disable the default error handler + // disable the default error handler... errorHandler: { error: () => ({ action: ErrorAction.Continue }), closed: () => ({ action: CloseAction.DoNotRestart }) - } - }; - } else { - mlcConfig.clientOptions = clientOptions; - } - + }, + // ...but allowm to override all options + ...this.languageClientConfig.clientOptions, + }, + messageTransports + }; this.languageClient = new MonacoLanguageClient(mlcConfig); const conOptions = this.languageClientConfig.connection.options; diff --git a/packages/wrapper/test/languageClientWrapper.test.ts b/packages/wrapper/test/languageClientWrapper.test.ts index d9a6b7367..74d230c59 100644 --- a/packages/wrapper/test/languageClientWrapper.test.ts +++ b/packages/wrapper/test/languageClientWrapper.test.ts @@ -24,7 +24,9 @@ describe('Test LanguageClientWrapper', () => { name: 'Langium LS', }); const languageClientConfig: LanguageClientConfig = { - clientOptionsOrLanguageIds: ['javascript'], + clientOptions: { + documentSelector: ['javascript'] + }, connection: { options: { $type: 'WorkerDirect', @@ -51,7 +53,9 @@ describe('Test LanguageClientWrapper', () => { const config = createWrapperConfigExtendedApp(); config.languageClientConfigs = { javascript: { - clientOptionsOrLanguageIds: ['javascript'], + clientOptions: { + documentSelector: ['javascript'] + }, connection: { options: { $type: 'WorkerDirect', @@ -84,7 +88,9 @@ describe('Test LanguageClientWrapper', () => { const config = createWrapperConfigExtendedApp(); config.languageClientConfigs = { javascript: { - clientOptionsOrLanguageIds: ['javascript'], + clientOptions: { + documentSelector: ['javascript'] + }, connection: { options: { $type: 'WebSocketUrl', @@ -104,7 +110,9 @@ describe('Test LanguageClientWrapper', () => { const config = createWrapperConfigExtendedApp(); config.languageClientConfigs = { javascript: { - clientOptionsOrLanguageIds: ['javascript'], + clientOptions: { + documentSelector: ['javascript'] + }, name: 'test-unreachable', connection: { options: { @@ -141,7 +149,9 @@ describe('Test LanguageClientWrapper', () => { const config = createWrapperConfigExtendedApp(); config.languageClientConfigs = { javascript: { - clientOptionsOrLanguageIds: ['javascript'], + clientOptions: { + documentSelector: ['javascript'] + }, connection: { options: { $type: 'WorkerConfig',