From 512809d7cae3ae2938dd71290c9460c981c40dd3 Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Mon, 26 Feb 2024 18:10:49 -0600 Subject: [PATCH 1/2] fix logging Signed-off-by: Jade Abraham --- src/ChapelLanguageClient.ts | 85 ++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 30 deletions(-) diff --git a/src/ChapelLanguageClient.ts b/src/ChapelLanguageClient.ts index ac51636..b8556b1 100644 --- a/src/ChapelLanguageClient.ts +++ b/src/ChapelLanguageClient.ts @@ -14,25 +14,31 @@ export enum LanguageClientState { } class ErrorHandlingClient extends vlc.LanguageClient { - errorHandler: (message: string, fatal: boolean, data?: any) => void; + infoHandler: (message: string, data?: any) => void; + warningHandler: (message: string, data?: any) => void; + errorHandler: (message: string, data?: any) => void; constructor( name: string, serverOptions: vlc.ServerOptions, clientOptions: vlc.LanguageClientOptions, - errorHandler: (message: string, fatal: boolean, data?: any) => void + infoHandler: (message: string, data?: any) => void, + warningHandler: (message: string, data?: any) => void, + errorHandler: (message: string, data?: any) => void ) { super(name, serverOptions, clientOptions); + this.infoHandler = infoHandler; + this.warningHandler = warningHandler; this.errorHandler = errorHandler; } override info(message: string, data?: any): void { - this.errorHandler(message, false, data); + this.infoHandler(message, data); } override warn(message: string, data?: any): void { - this.errorHandler(message, false, data); + this.warningHandler(message, data); } override error(message: string, data?: any): void { - this.errorHandler(message, true, data); + this.errorHandler(message, data); } } @@ -180,11 +186,25 @@ export abstract class ChapelLanguageClient { const errorLogger = (message: string) => { this.logger.error(`${this.name}: ${message}`); }; - const errorHandler = ( - message: string, - fatal: boolean = false, - data?: any - ) => { + const infoLogger = (message: string, data?: any) => { + if (data) { + this.logger.info( + `${this.name}: ${message} - ${JSON.stringify(data, undefined, 2)}` + ); + } else { + this.logger.info(`${this.name}: ${message}`); + } + }; + const warningLogger = (message: string, data?: any) => { + if (data) { + this.logger.warn( + `${this.name}: ${message} - ${JSON.stringify(data, undefined, 2)}` + ); + } else { + this.logger.warn(`${this.name}: ${message}`); + } + }; + const errorHandler = (message: string, data?: any) => { if (data) { errorLogger(`${message} - ${JSON.stringify(data, undefined, 2)}`); } else { @@ -198,26 +218,24 @@ export abstract class ChapelLanguageClient { } } - if (fatal) { - this.stop().finally(() => { - this.state = LanguageClientState.ERRORED; + this.stop().finally(() => { + this.state = LanguageClientState.ERRORED; - vscode.window - .showErrorMessage( - `${this.name} encountered an unrecoverable error`, - "Restart", - "Show Log", - "Ok" - ) - .then((value) => { - if (value === "Restart") { - this.restart(); - } else if (value === "Show Log") { - this.logger.show(); - } - }); - }); - } + vscode.window + .showErrorMessage( + `${this.name} encountered an unrecoverable error`, + "Restart", + "Show Log", + "Ok" + ) + .then((value) => { + if (value === "Restart") { + this.restart(); + } else if (value === "Show Log") { + this.logger.show(); + } + }); + }); }; const clientOptions: vlc.LanguageClientOptions = { @@ -258,6 +276,8 @@ export abstract class ChapelLanguageClient { this.name, serverOptions, clientOptions, + infoLogger, + warningLogger, errorHandler ); @@ -305,7 +325,12 @@ export class ChplCheckClient extends ChapelLanguageClient { } export class CLSClient extends ChapelLanguageClient { getToolPath(): string { - return path.join(this.chplhome, "tools", "chpl-language-server", "chpl-language-server"); + return path.join( + this.chplhome, + "tools", + "chpl-language-server", + "chpl-language-server" + ); } alwaysArguments(): Array { let args = []; From 3cca8d6e2bc98061008eae53a126173eb673e8d8 Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Tue, 27 Feb 2024 07:35:01 -0600 Subject: [PATCH 2/2] fix title Signed-off-by: Jade Abraham --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eaa98e8..8e855d1 100644 --- a/package.json +++ b/package.json @@ -104,7 +104,7 @@ "configuration": [ { "type": "object", - "title": "chapel configuration", + "title": "Chapel Language Support", "properties": { "chapel.CHPL_HOME": { "scope": "window",