editor/code: Remove unused sendRequestWithRetry

This commit is contained in:
Tetsuharu Ohzeki 2023-07-10 23:13:16 +09:00
parent fd31006646
commit a66b7e3eba

View File

@ -1,4 +1,3 @@
import * as lc from "vscode-languageclient/node";
import * as vscode from "vscode"; import * as vscode from "vscode";
import { strict as nativeAssert } from "assert"; import { strict as nativeAssert } from "assert";
import { exec, ExecOptions, spawnSync } from "child_process"; import { exec, ExecOptions, spawnSync } from "child_process";
@ -57,41 +56,6 @@ export const log = new (class {
} }
})(); })();
export async function sendRequestWithRetry<TParam, TRet>(
client: lc.LanguageClient,
reqType: lc.RequestType<TParam, TRet, unknown>,
param: TParam,
token?: vscode.CancellationToken
): Promise<TRet> {
// 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) { export function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms)); return new Promise((resolve) => setTimeout(resolve, ms));
} }