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/rollup.config.js | 2 +- editors/code/src/ctx.ts | 15 +++++++++++++++ editors/code/src/inlay_hints.ts | 7 +------ 3 files changed, 17 insertions(+), 7 deletions(-) (limited to 'editors/code') diff --git a/editors/code/rollup.config.js b/editors/code/rollup.config.js index 4c001f899..14fb9e085 100644 --- a/editors/code/rollup.config.js +++ b/editors/code/rollup.config.js @@ -13,7 +13,7 @@ export default { commonjs({ namedExports: { // squelch missing import warnings - 'vscode-languageclient': ['CreateFile', 'RenameFile'] + 'vscode-languageclient': ['CreateFile', 'RenameFile', 'ErrorCodes'] } }) ], 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; diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index aae9de69c..16faea22e 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts @@ -5,8 +5,6 @@ import { Ctx } from './ctx'; export function activateInlayHints(ctx: Ctx) { const hintsUpdater = new HintsUpdater(ctx); - console.log('activateInlayHints'); - vscode.window.onDidChangeVisibleTextEditors(async _ => { await hintsUpdater.refresh(); }, ctx.subscriptions); @@ -69,7 +67,6 @@ class HintsUpdater { private async refreshEditor(editor: vscode.TextEditor): Promise { const newHints = await this.queryHints(editor.document.uri.toString()); - const newDecorations = (newHints ? newHints : []).map(hint => ({ range: hint.range, renderOptions: { @@ -101,9 +98,7 @@ class HintsUpdater { const request: InlayHintsParams = { textDocument: { uri: documentUri }, }; - await this.ctx.client.onReady(); - - return this.ctx.client.sendRequest( + return this.ctx.sendRequestWithRetry( 'rust-analyzer/inlayHints', request, ); -- cgit v1.2.3