mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Don't request inline hints repeatedly
This commit is contained in:
parent
23bac12062
commit
cdd7118cbf
2 changed files with 26 additions and 10 deletions
|
@ -62,20 +62,23 @@ export class Ctx {
|
|||
this.extCtx.subscriptions.push(d);
|
||||
}
|
||||
|
||||
async sendRequestWithRetry<R>(method: string, param: any): Promise<R> {
|
||||
async sendRequestWithRetry<R>(method: string, param: any, token: vscode.CancellationToken): Promise<R> {
|
||||
await this.client.onReady();
|
||||
const nRetries = 3;
|
||||
for (let triesLeft = nRetries; ; triesLeft--) {
|
||||
for (const delay of [2, 4, 6, 8, 10, null]) {
|
||||
try {
|
||||
return await this.client.sendRequest(method, param);
|
||||
return await this.client.sendRequest(method, param, token);
|
||||
} catch (e) {
|
||||
if (e.code === lc.ErrorCodes.ContentModified && triesLeft > 0) {
|
||||
if (e.code === lc.ErrorCodes.ContentModified && delay !== null) {
|
||||
await sleep(10 * (1 << delay))
|
||||
continue;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
throw 'unreachable'
|
||||
}
|
||||
}
|
||||
|
||||
export type Cmd = (...args: any[]) => any;
|
||||
|
||||
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue