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 /editors | |
parent | 08c5d157f9a24f0094c90c556019a20bf85e5a07 (diff) |
Retry inlay hints on content modified error
Diffstat (limited to 'editors')
-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 |
3 files changed, 17 insertions, 7 deletions
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 | ); |