diff options
author | Aleksey Kladov <[email protected]> | 2019-12-30 21:18:16 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-12-30 21:20:04 +0000 |
commit | 23bac120625ca96402426e241c91ed5f3d7ccc02 (patch) | |
tree | 271429fe8639f603a91dd20cfdd950a3f5887e12 | |
parent | 08c5d157f9a24f0094c90c556019a20bf85e5a07 (diff) |
Retry inlay hints on content modified error
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 15 | ||||
-rw-r--r-- | editors/code/rollup.config.js | 2 | ||||
-rw-r--r-- | editors/code/src/ctx.ts | 15 | ||||
-rw-r--r-- | 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 | |||
709 | Ok(lsp_error) => Response::new_err(id, lsp_error.code, lsp_error.message), | 709 | Ok(lsp_error) => Response::new_err(id, lsp_error.code, lsp_error.message), |
710 | Err(e) => { | 710 | Err(e) => { |
711 | if is_canceled(&e) { | 711 | if is_canceled(&e) { |
712 | // FIXME: When https://github.com/Microsoft/vscode-languageserver-node/issues/457 | 712 | Response::new_err( |
713 | // gets fixed, we can return the proper response. | 713 | id, |
714 | // This works around the issue where "content modified" error would continuously | 714 | ErrorCode::ContentModified as i32, |
715 | // show an message pop-up in VsCode | 715 | "content modified".to_string(), |
716 | // Response::err( | 716 | ) |
717 | // id, | ||
718 | // ErrorCode::ContentModified as i32, | ||
719 | // "content modified".to_string(), | ||
720 | // ) | ||
721 | Response::new_ok(id, ()) | ||
722 | } else { | 717 | } else { |
723 | Response::new_err(id, ErrorCode::InternalError as i32, e.to_string()) | 718 | Response::new_err(id, ErrorCode::InternalError as i32, e.to_string()) |
724 | } | 719 | } |
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 { | |||
13 | commonjs({ | 13 | commonjs({ |
14 | namedExports: { | 14 | namedExports: { |
15 | // squelch missing import warnings | 15 | // squelch missing import warnings |
16 | 'vscode-languageclient': ['CreateFile', 'RenameFile'] | 16 | 'vscode-languageclient': ['CreateFile', 'RenameFile', 'ErrorCodes'] |
17 | } | 17 | } |
18 | }) | 18 | }) |
19 | ], | 19 | ], |
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 { | |||
61 | pushCleanup(d: { dispose(): any }) { | 61 | pushCleanup(d: { dispose(): any }) { |
62 | this.extCtx.subscriptions.push(d); | 62 | this.extCtx.subscriptions.push(d); |
63 | } | 63 | } |
64 | |||
65 | async sendRequestWithRetry<R>(method: string, param: any): Promise<R> { | ||
66 | await this.client.onReady(); | ||
67 | const nRetries = 3; | ||
68 | for (let triesLeft = nRetries; ; triesLeft--) { | ||
69 | try { | ||
70 | return await this.client.sendRequest(method, param); | ||
71 | } catch (e) { | ||
72 | if (e.code === lc.ErrorCodes.ContentModified && triesLeft > 0) { | ||
73 | continue; | ||
74 | } | ||
75 | throw e; | ||
76 | } | ||
77 | } | ||
78 | } | ||
64 | } | 79 | } |
65 | 80 | ||
66 | export type Cmd = (...args: any[]) => any; | 81 | 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'; | |||
5 | 5 | ||
6 | export function activateInlayHints(ctx: Ctx) { | 6 | export function activateInlayHints(ctx: Ctx) { |
7 | const hintsUpdater = new HintsUpdater(ctx); | 7 | const hintsUpdater = new HintsUpdater(ctx); |
8 | console.log('activateInlayHints'); | ||
9 | |||
10 | vscode.window.onDidChangeVisibleTextEditors(async _ => { | 8 | vscode.window.onDidChangeVisibleTextEditors(async _ => { |
11 | await hintsUpdater.refresh(); | 9 | await hintsUpdater.refresh(); |
12 | }, ctx.subscriptions); | 10 | }, ctx.subscriptions); |
@@ -69,7 +67,6 @@ class HintsUpdater { | |||
69 | 67 | ||
70 | private async refreshEditor(editor: vscode.TextEditor): Promise<void> { | 68 | private async refreshEditor(editor: vscode.TextEditor): Promise<void> { |
71 | const newHints = await this.queryHints(editor.document.uri.toString()); | 69 | const newHints = await this.queryHints(editor.document.uri.toString()); |
72 | |||
73 | const newDecorations = (newHints ? newHints : []).map(hint => ({ | 70 | const newDecorations = (newHints ? newHints : []).map(hint => ({ |
74 | range: hint.range, | 71 | range: hint.range, |
75 | renderOptions: { | 72 | renderOptions: { |
@@ -101,9 +98,7 @@ class HintsUpdater { | |||
101 | const request: InlayHintsParams = { | 98 | const request: InlayHintsParams = { |
102 | textDocument: { uri: documentUri }, | 99 | textDocument: { uri: documentUri }, |
103 | }; | 100 | }; |
104 | await this.ctx.client.onReady(); | 101 | return this.ctx.sendRequestWithRetry<InlayHint[] | null>( |
105 | |||
106 | return this.ctx.client.sendRequest<InlayHint[] | null>( | ||
107 | 'rust-analyzer/inlayHints', | 102 | 'rust-analyzer/inlayHints', |
108 | request, | 103 | request, |
109 | ); | 104 | ); |