From efbbc903e68aaf32ee1fba5537769070cd2d01e8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Dec 2019 20:46:14 +0100 Subject: Add config to Ctx --- editors/code/src/ctx.ts | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'editors/code/src/ctx.ts') diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index c3a3583b5..ca4319064 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -1,6 +1,7 @@ import * as vscode from 'vscode'; import * as lc from 'vscode-languageclient'; import { Server } from './server'; +import { Config } from './config'; export class Ctx { private extCtx: vscode.ExtensionContext; @@ -13,6 +14,10 @@ export class Ctx { return Server.client; } + get config(): Config { + return Server.config; + } + get activeRustEditor(): vscode.TextEditor | undefined { const editor = vscode.window.activeTextEditor; return editor && editor.document.languageId === 'rust' -- cgit v1.2.3 From 23bac120625ca96402426e241c91ed5f3d7ccc02 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Dec 2019 22:18:16 +0100 Subject: Retry inlay hints on content modified error --- editors/code/src/ctx.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'editors/code/src/ctx.ts') diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index ca4319064..75b3542f4 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -61,6 +61,21 @@ export class Ctx { pushCleanup(d: { dispose(): any }) { this.extCtx.subscriptions.push(d); } + + async sendRequestWithRetry(method: string, param: any): Promise { + await this.client.onReady(); + const nRetries = 3; + for (let triesLeft = nRetries; ; triesLeft--) { + try { + return await this.client.sendRequest(method, param); + } catch (e) { + if (e.code === lc.ErrorCodes.ContentModified && triesLeft > 0) { + continue; + } + throw e; + } + } + } } export type Cmd = (...args: any[]) => any; -- cgit v1.2.3 From cdd7118cbf23e21c376092b3b2734407004b8dbf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Dec 2019 22:53:21 +0100 Subject: Don't request inline hints repeatedly --- editors/code/src/ctx.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'editors/code/src/ctx.ts') diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index 75b3542f4..d3ef27e43 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -62,20 +62,23 @@ export class Ctx { this.extCtx.subscriptions.push(d); } - async sendRequestWithRetry(method: string, param: any): Promise { + async sendRequestWithRetry(method: string, param: any, token: vscode.CancellationToken): Promise { 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)) -- cgit v1.2.3