From fd31006646b3c9014b1770cf02ab2e9bca59c1e8 Mon Sep 17 00:00:00 2001 From: Tetsuharu Ohzeki Date: Mon, 10 Jul 2023 23:12:42 +0900 Subject: editor/code: Assert types in catch in `sendRequestWithRetry()` properly --- editors/code/src/util.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts index b6b779e2660..688e3873ab4 100644 --- a/editors/code/src/util.ts +++ b/editors/code/src/util.ts @@ -69,20 +69,24 @@ export async function sendRequestWithRetry( return await (token ? client.sendRequest(reqType, param, token) : client.sendRequest(reqType, param)); - } catch (error) { + } catch (error: unknown) { if (delay === null) { log.warn("LSP request timed out", { method: reqType.method, param, error }); throw error; } - if (error.code === lc.LSPErrorCodes.RequestCancelled) { - throw error; - } - if (error.code !== lc.LSPErrorCodes.ContentModified) { - log.warn("LSP request failed", { method: reqType.method, param, error }); - throw error; + if (error instanceof lc.ResponseError) { + switch (error.code) { + case lc.LSPErrorCodes.RequestCancelled: + throw error; + case lc.LSPErrorCodes.ContentModified: + await sleep(delay); + continue; + } } - await sleep(delay); + + log.warn("LSP request failed", { method: reqType.method, param, error }); + throw error; } } throw "unreachable"; -- cgit 1.4.1-3-g733a5 From a66b7e3eba90690ed2860125c7d47932fddaff22 Mon Sep 17 00:00:00 2001 From: Tetsuharu Ohzeki Date: Mon, 10 Jul 2023 23:13:16 +0900 Subject: editor/code: Remove unused `sendRequestWithRetry` --- editors/code/src/util.ts | 36 ------------------------------------ 1 file changed, 36 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts index 688e3873ab4..b6240234aa6 100644 --- a/editors/code/src/util.ts +++ b/editors/code/src/util.ts @@ -1,4 +1,3 @@ -import * as lc from "vscode-languageclient/node"; import * as vscode from "vscode"; import { strict as nativeAssert } from "assert"; import { exec, ExecOptions, spawnSync } from "child_process"; @@ -57,41 +56,6 @@ export const log = new (class { } })(); -export async function sendRequestWithRetry( - client: lc.LanguageClient, - reqType: lc.RequestType, - param: TParam, - token?: vscode.CancellationToken -): Promise { - // The sequence is `10 * (2 ** (2 * n))` where n is 1, 2, 3... - for (const delay of [40, 160, 640, 2560, 10240, null]) { - try { - return await (token - ? client.sendRequest(reqType, param, token) - : client.sendRequest(reqType, param)); - } catch (error: unknown) { - if (delay === null) { - log.warn("LSP request timed out", { method: reqType.method, param, error }); - throw error; - } - - if (error instanceof lc.ResponseError) { - switch (error.code) { - case lc.LSPErrorCodes.RequestCancelled: - throw error; - case lc.LSPErrorCodes.ContentModified: - await sleep(delay); - continue; - } - } - - log.warn("LSP request failed", { method: reqType.method, param, error }); - throw error; - } - } - throw "unreachable"; -} - export function sleep(ms: number) { return new Promise((resolve) => setTimeout(resolve, ms)); } -- cgit 1.4.1-3-g733a5 From 444bc5b3ba366d2eab252e2c4f5c956a5e21df58 Mon Sep 17 00:00:00 2001 From: Tetsuharu Ohzeki Date: Mon, 10 Jul 2023 23:03:08 +0900 Subject: editor/code: Enable TypeScript's `--useUnknownInCatchVariables` option see: https://www.typescriptlang.org/tsconfig#useUnknownInCatchVariables --- editors/code/src/commands.ts | 4 ++-- editors/code/tests/unit/index.ts | 3 +++ editors/code/tsconfig.json | 1 - 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'editors/code/src') diff --git a/editors/code/src/commands.ts b/editors/code/src/commands.ts index 17202e5345a..94ec5e99c6a 100644 --- a/editors/code/src/commands.ts +++ b/editors/code/src/commands.ts @@ -373,7 +373,7 @@ export function ssr(ctx: CtxInit): Cmd { selections, }); } catch (e) { - return e.toString(); + return String(e); } return null; }, @@ -1156,7 +1156,7 @@ export function viewMemoryLayout(ctx: CtxInit): Cmd { Document -