From 3b4f572c590d2b9ad7558dfa83bbca0e38f9b964 Mon Sep 17 00:00:00 2001 From: Kai Salmen Date: Mon, 23 Sep 2024 11:07:27 +0200 Subject: [PATCH] Implemented review comments --- packages/client/src/commonTypes.ts | 42 ++++++++----------- packages/wrapper/src/languageClientWrapper.ts | 11 +++-- packages/wrapper/src/wrapper.ts | 20 ++++----- 3 files changed, 35 insertions(+), 38 deletions(-) diff --git a/packages/client/src/commonTypes.ts b/packages/client/src/commonTypes.ts index 7a86ef88e..bdc31dbad 100644 --- a/packages/client/src/commonTypes.ts +++ b/packages/client/src/commonTypes.ts @@ -5,22 +5,23 @@ import { MonacoLanguageClient } from './client.js'; -export type WebSocketCallOptions = { +export type ConnetionConfigOptions = WebSocketConfigOptionsDirect | WebSocketConfigOptionsParams | WebSocketConfigOptionsUrl | WorkerConfigOptionsParams | WorkerConfigOptionsDirect; + +export interface WebSocketCallOptions { /** Adds handle on languageClient */ onCall: (languageClient?: MonacoLanguageClient) => void; /** Reports Status Of Language Client */ reportStatus?: boolean; } -export type LanguageClientRestartOptions = { - retries: number; - timeout: number; - keepWorker?: boolean; +export interface WebSocketConfigOptionsDirect { + $type: 'WebSocketDirect' + webSocket: WebSocket + startOptions?: WebSocketCallOptions; + stopOptions?: WebSocketCallOptions; } -export type ConnetionConfigOptions = (WebSocketConfigOptionsDirect | WebSocketConfigOptionsParams | WebSocketConfigOptionsUrl | WorkerConfigOptionsParams | WorkerConfigOptionsDirect); - -export type WebSocketUrlParams = { +export interface WebSocketUrlParams { secured: boolean; host: string; port?: number; @@ -28,39 +29,32 @@ export type WebSocketUrlParams = { extraParams?: Record>; } -export type WebSocketUrlString = { - url: string; -} - -export type WebSocketConfigOptionsDirect = { - $type: 'WebSocketDirect' - webSocket: WebSocket +export interface WebSocketConfigOptionsParams extends WebSocketUrlParams { + $type: 'WebSocketParams' startOptions?: WebSocketCallOptions; stopOptions?: WebSocketCallOptions; } -export type WebSocketConfigOptionsParams = WebSocketUrlParams & { - $type: 'WebSocketParams' - startOptions?: WebSocketCallOptions; - stopOptions?: WebSocketCallOptions; +export interface WebSocketUrlString { + url: string; } -export type WebSocketConfigOptionsUrl = WebSocketUrlString & { +export interface WebSocketConfigOptionsUrl extends WebSocketUrlString { $type: 'WebSocketUrl' startOptions?: WebSocketCallOptions; stopOptions?: WebSocketCallOptions; } -export type WorkerConfigOptionsParams = { +export interface WorkerConfigOptionsParams { $type: 'WorkerConfig' url: URL; type: 'classic' | 'module'; messagePort?: MessagePort; workerName?: string; -}; +} -export type WorkerConfigOptionsDirect = { +export interface WorkerConfigOptionsDirect { $type: 'WorkerDirect'; worker: Worker; messagePort?: MessagePort; -}; +} diff --git a/packages/wrapper/src/languageClientWrapper.ts b/packages/wrapper/src/languageClientWrapper.ts index c465dea11..73fd4854e 100644 --- a/packages/wrapper/src/languageClientWrapper.ts +++ b/packages/wrapper/src/languageClientWrapper.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See LICENSE in the package root for license information. * ------------------------------------------------------------------------------------------ */ -import { MonacoLanguageClient, LanguageClientRestartOptions, ConnetionConfigOptions, WorkerConfigOptionsDirect, WorkerConfigOptionsParams } from 'monaco-languageclient'; +import { MonacoLanguageClient, ConnetionConfigOptions, WorkerConfigOptionsDirect, WorkerConfigOptionsParams } from 'monaco-languageclient'; import { Logger } from 'monaco-languageclient/tools'; import { BrowserMessageReader, BrowserMessageWriter } from 'vscode-languageserver-protocol/browser.js'; import { CloseAction, ErrorAction, LanguageClientOptions, MessageTransports, State } from 'vscode-languageclient/browser.js'; @@ -23,10 +23,16 @@ export type LanguageClientConfig = { restartOptions?: LanguageClientRestartOptions; } +export type LanguageClientRestartOptions = { + retries: number; + timeout: number; + keepWorker?: boolean; +} + export type LanguageClientError = { message: string; error: Error | string; -}; +} export class LanguageClientWrapper { @@ -70,7 +76,6 @@ export class LanguageClientWrapper { return Promise.resolve(); } - // eslint-disable-next-line no-async-promise-executor return new Promise((resolve, reject) => { const conConfig = this.languageClientConfig.connection; const conOptions = conConfig.options; diff --git a/packages/wrapper/src/wrapper.ts b/packages/wrapper/src/wrapper.ts index 51a4a8fec..6282c9575 100644 --- a/packages/wrapper/src/wrapper.ts +++ b/packages/wrapper/src/wrapper.ts @@ -77,10 +77,9 @@ export class MonacoEditorLanguageClientWrapper { logger: this.logger }); - const lccs = wrapperConfig.languageClientConfigs; - if (lccs !== undefined && Object.entries(lccs).length > 0) { - - for (const [languageId, lcc] of Object.entries(lccs)) { + const lccEntries = Object.entries(wrapperConfig.languageClientConfigs ?? {}); + if (lccEntries.length > 0) { + for (const [languageId, lcc] of lccEntries) { const lcw = new LanguageClientWrapper({ languageClientConfig: lcc, logger: this.logger @@ -217,24 +216,23 @@ export class MonacoEditorLanguageClientWrapper { /** * Disposes all application and editor resources, plus the languageclient (if used). */ - async dispose(disposeLanguageClients: boolean = true): Promise { + async dispose(disposeLanguageClients: boolean = true) { this.markStopping(); this.editorApp?.disposeApp(); + this.editorApp = undefined; if (disposeLanguageClients) { + const allPromises: Array> = []; for (const lcw of this.languageClientWrappers.values()) { if (lcw.haveLanguageClient()) { - await lcw.disposeLanguageClient(false); + allPromises.push(lcw.disposeLanguageClient(false)); } - this.editorApp = undefined; - await Promise.resolve('Monaco editor and languageclient completed disposed.'); } - } else { - await Promise.resolve('Monaco editor has been disposed.'); + await Promise.all(allPromises); } - this.initDone = false; + this.initDone = false; this.markStopped(); }