mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
vscode: gracefully handle cancellation errors
This commit is contained in:
parent
838ad6bcfb
commit
4cee7cddc8
4 changed files with 60 additions and 44 deletions
|
@ -52,24 +52,3 @@ export interface Disposable {
|
|||
dispose(): void;
|
||||
}
|
||||
export type Cmd = (...args: any[]) => unknown;
|
||||
|
||||
export async function sendRequestWithRetry<R>(
|
||||
client: lc.LanguageClient,
|
||||
method: string,
|
||||
param: unknown,
|
||||
token?: vscode.CancellationToken,
|
||||
): Promise<R> {
|
||||
for (const delay of [2, 4, 6, 8, 10, null]) {
|
||||
try {
|
||||
return await (token ? client.sendRequest(method, param, token) : client.sendRequest(method, param));
|
||||
} catch (err) {
|
||||
if (delay === null || err.code !== lc.ErrorCodes.ContentModified) {
|
||||
throw err;
|
||||
}
|
||||
await sleep(10 * (1 << delay));
|
||||
}
|
||||
}
|
||||
throw 'unreachable';
|
||||
}
|
||||
|
||||
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue