From da6e723f8be62fea91663258cc269167f4e24c0a Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Thu, 18 Aug 2022 22:00:20 +0200 Subject: [PATCH] refactor: use lsp lib helper methods --- src/lsp-client.ts | 18 ++++-------------- src/test-utils.ts | 8 -------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/src/lsp-client.ts b/src/lsp-client.ts index c2cc2188..44cd1171 100644 --- a/src/lsp-client.ts +++ b/src/lsp-client.ts @@ -19,11 +19,9 @@ export interface LspClient { createProgressReporter(token?: lsp.CancellationToken, workDoneProgress?: lsp.WorkDoneProgressReporter): Promise; withProgress(options: WithProgressOptions, task: (progress: lsp.WorkDoneProgressReporter) => Promise): Promise; publishDiagnostics(args: lsp.PublishDiagnosticsParams): void; - showMessage(args: lsp.ShowMessageParams): void; showErrorMessage(message: string): void; logMessage(args: lsp.LogMessageParams): void; applyWorkspaceEdit(args: lsp.ApplyWorkspaceEditParams): Promise; - telemetry(args: any): void; rename(args: lsp.TextDocumentPositionParams): Promise; } @@ -52,12 +50,8 @@ export class LspClientImpl implements LspClient { }); } - publishDiagnostics(args: lsp.PublishDiagnosticsParams): void { - this.connection.sendNotification(lsp.PublishDiagnosticsNotification.type, args); - } - - showMessage(args: lsp.ShowMessageParams): void { - this.connection.sendNotification(lsp.ShowMessageNotification.type, args); + publishDiagnostics(params: lsp.PublishDiagnosticsParams): void { + this.connection.sendDiagnostics(params); } showErrorMessage(message: string): void { @@ -68,12 +62,8 @@ export class LspClientImpl implements LspClient { this.connection.sendNotification(lsp.LogMessageNotification.type, args); } - telemetry(args: any): void { - this.connection.sendNotification(lsp.TelemetryEventNotification.type, args); - } - - async applyWorkspaceEdit(args: lsp.ApplyWorkspaceEditParams): Promise { - return this.connection.sendRequest(lsp.ApplyWorkspaceEditRequest.type, args); + async applyWorkspaceEdit(params: lsp.ApplyWorkspaceEditParams): Promise { + return this.connection.workspace.applyEdit(params); } async rename(args: lsp.TextDocumentPositionParams): Promise { diff --git a/src/test-utils.ts b/src/test-utils.ts index e097b494..9ca2ec56 100644 --- a/src/test-utils.ts +++ b/src/test-utils.ts @@ -128,10 +128,6 @@ class TestLspClient implements LspClient { return this.options.publishDiagnostics(args); } - showMessage(args: lsp.ShowMessageParams): void { - throw args; // should not be called. - } - showErrorMessage(message: string) { this.logger.error(`[showErrorMessage] ${message}`); } @@ -140,10 +136,6 @@ class TestLspClient implements LspClient { this.logger.log('logMessage', JSON.stringify(args)); } - telemetry(args: any): void { - this.logger.log('telemetry', JSON.stringify(args)); - } - addApplyWorkspaceEditListener(listener: (args: lsp.ApplyWorkspaceEditParams) => void): void { this.workspaceEditsListener = listener; }