diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-30 21:57:08 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-30 21:57:08 +0000 |
commit | c3d74744cdae29aa6a6bfa0cd7ab64b8b251e287 (patch) | |
tree | bf53aac74110d30eba6da346e764e003ffd8b9c4 /editors/code/src/ctx.ts | |
parent | 17dda0972a68dd88a766c223390317dc2cb3ea00 (diff) | |
parent | cdd7118cbf23e21c376092b3b2734407004b8dbf (diff) |
Merge #2694
2694: Refactor inlay hints r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'editors/code/src/ctx.ts')
-rw-r--r-- | editors/code/src/ctx.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index c3a3583b5..d3ef27e43 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import * as vscode from 'vscode'; | 1 | import * as vscode from 'vscode'; |
2 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
3 | import { Server } from './server'; | 3 | import { Server } from './server'; |
4 | import { Config } from './config'; | ||
4 | 5 | ||
5 | export class Ctx { | 6 | export class Ctx { |
6 | private extCtx: vscode.ExtensionContext; | 7 | private extCtx: vscode.ExtensionContext; |
@@ -13,6 +14,10 @@ export class Ctx { | |||
13 | return Server.client; | 14 | return Server.client; |
14 | } | 15 | } |
15 | 16 | ||
17 | get config(): Config { | ||
18 | return Server.config; | ||
19 | } | ||
20 | |||
16 | get activeRustEditor(): vscode.TextEditor | undefined { | 21 | get activeRustEditor(): vscode.TextEditor | undefined { |
17 | const editor = vscode.window.activeTextEditor; | 22 | const editor = vscode.window.activeTextEditor; |
18 | return editor && editor.document.languageId === 'rust' | 23 | return editor && editor.document.languageId === 'rust' |
@@ -56,6 +61,24 @@ export class Ctx { | |||
56 | pushCleanup(d: { dispose(): any }) { | 61 | pushCleanup(d: { dispose(): any }) { |
57 | this.extCtx.subscriptions.push(d); | 62 | this.extCtx.subscriptions.push(d); |
58 | } | 63 | } |
64 | |||
65 | async sendRequestWithRetry<R>(method: string, param: any, token: vscode.CancellationToken): Promise<R> { | ||
66 | await this.client.onReady(); | ||
67 | for (const delay of [2, 4, 6, 8, 10, null]) { | ||
68 | try { | ||
69 | return await this.client.sendRequest(method, param, token); | ||
70 | } catch (e) { | ||
71 | if (e.code === lc.ErrorCodes.ContentModified && delay !== null) { | ||
72 | await sleep(10 * (1 << delay)) | ||
73 | continue; | ||
74 | } | ||
75 | throw e; | ||
76 | } | ||
77 | } | ||
78 | throw 'unreachable' | ||
79 | } | ||
59 | } | 80 | } |
60 | 81 | ||
61 | export type Cmd = (...args: any[]) => any; | 82 | export type Cmd = (...args: any[]) => any; |
83 | |||
84 | const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)) | ||