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 --- crates/ra_lsp_server/src/main_loop.rs | 15 +++++---------- editors/code/rollup.config.js | 2 +- editors/code/src/ctx.ts | 15 +++++++++++++++ editors/code/src/inlay_hints.ts | 7 +------ 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index af1a487de..4336583fe 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -709,16 +709,11 @@ where Ok(lsp_error) => Response::new_err(id, lsp_error.code, lsp_error.message), Err(e) => { if is_canceled(&e) { - // FIXME: When https://github.com/Microsoft/vscode-languageserver-node/issues/457 - // gets fixed, we can return the proper response. - // This works around the issue where "content modified" error would continuously - // show an message pop-up in VsCode - // Response::err( - // id, - // ErrorCode::ContentModified as i32, - // "content modified".to_string(), - // ) - Response::new_ok(id, ()) + Response::new_err( + id, + ErrorCode::ContentModified as i32, + "content modified".to_string(), + ) } else { Response::new_err(id, ErrorCode::InternalError as i32, e.to_string()) } 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