Skip to content

Commit

Permalink
Implemented review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Sep 23, 2024
1 parent f4da090 commit 3b4f572
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 38 deletions.
42 changes: 18 additions & 24 deletions packages/client/src/commonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,56 @@

import { MonacoLanguageClient } from './client.js';

export type WebSocketCallOptions = {
export type ConnetionConfigOptions = WebSocketConfigOptionsDirect | WebSocketConfigOptionsParams | WebSocketConfigOptionsUrl | WorkerConfigOptionsParams | WorkerConfigOptionsDirect;

This comment has been minimized.

Copy link
@nametable

nametable Nov 13, 2024

Typo here: ConnetionConfigOptions should probably be ConnectionConfigOptions

This comment has been minimized.

Copy link
@kaisalmen

kaisalmen Nov 13, 2024

Author Collaborator

Thanks, I correct it with the next commit / PR.


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;
path?: string;
extraParams?: Record<string, string | number | Array<string | number>>;
}

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;
};
}
11 changes: 8 additions & 3 deletions packages/wrapper/src/languageClientWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {

Expand Down Expand Up @@ -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;
Expand Down
20 changes: 9 additions & 11 deletions packages/wrapper/src/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -217,24 +216,23 @@ export class MonacoEditorLanguageClientWrapper {
/**
* Disposes all application and editor resources, plus the languageclient (if used).
*/
async dispose(disposeLanguageClients: boolean = true): Promise<void> {
async dispose(disposeLanguageClients: boolean = true) {
this.markStopping();

this.editorApp?.disposeApp();
this.editorApp = undefined;

if (disposeLanguageClients) {
const allPromises: Array<Promise<void>> = [];
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();
}

Expand Down

0 comments on commit 3b4f572

Please sign in to comment.