diff options
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/src/config.ts | 1 | ||||
-rw-r--r-- | editors/code/src/ctx.ts | 12 | ||||
-rw-r--r-- | editors/code/src/inlay_hints.ts | 45 |
3 files changed, 28 insertions, 30 deletions
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index 70cb0a612..53e2a414b 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -44,7 +44,6 @@ export class Config { | |||
44 | this.refreshConfig(); | 44 | this.refreshConfig(); |
45 | } | 45 | } |
46 | 46 | ||
47 | |||
48 | private refreshConfig() { | 47 | private refreshConfig() { |
49 | this.cfg = vscode.workspace.getConfiguration(Config.rootSection); | 48 | this.cfg = vscode.workspace.getConfiguration(Config.rootSection); |
50 | console.log("Using configuration:", this.cfg); | 49 | console.log("Using configuration:", this.cfg); |
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index 9fcf2ec38..ff6245f78 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts | |||
@@ -91,15 +91,11 @@ export async function sendRequestWithRetry<R>( | |||
91 | for (const delay of [2, 4, 6, 8, 10, null]) { | 91 | for (const delay of [2, 4, 6, 8, 10, null]) { |
92 | try { | 92 | try { |
93 | return await (token ? client.sendRequest(method, param, token) : client.sendRequest(method, param)); | 93 | return await (token ? client.sendRequest(method, param, token) : client.sendRequest(method, param)); |
94 | } catch (e) { | 94 | } catch (err) { |
95 | if ( | 95 | if (delay === null || err.code !== lc.ErrorCodes.ContentModified) { |
96 | e.code === lc.ErrorCodes.ContentModified && | 96 | throw err; |
97 | delay !== null | ||
98 | ) { | ||
99 | await sleep(10 * (1 << delay)); | ||
100 | continue; | ||
101 | } | 97 | } |
102 | throw e; | 98 | await sleep(10 * (1 << delay)); |
103 | } | 99 | } |
104 | } | 100 | } |
105 | throw 'unreachable'; | 101 | throw 'unreachable'; |
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts index 12d7ddf0d..3896878cd 100644 --- a/editors/code/src/inlay_hints.ts +++ b/editors/code/src/inlay_hints.ts | |||
@@ -38,7 +38,7 @@ interface InlayHintsParams { | |||
38 | 38 | ||
39 | interface InlayHint { | 39 | interface InlayHint { |
40 | range: vscode.Range; | 40 | range: vscode.Range; |
41 | kind: string; | 41 | kind: "TypeHint" | "ParameterHint"; |
42 | label: string; | 42 | label: string; |
43 | } | 43 | } |
44 | 44 | ||
@@ -55,7 +55,7 @@ const parameterHintDecorationType = vscode.window.createTextEditorDecorationType | |||
55 | }); | 55 | }); |
56 | 56 | ||
57 | class HintsUpdater { | 57 | class HintsUpdater { |
58 | private pending: Map<string, vscode.CancellationTokenSource> = new Map(); | 58 | private pending = new Map<string, vscode.CancellationTokenSource>(); |
59 | private ctx: Ctx; | 59 | private ctx: Ctx; |
60 | private enabled: boolean; | 60 | private enabled: boolean; |
61 | 61 | ||
@@ -64,30 +64,36 @@ class HintsUpdater { | |||
64 | this.enabled = ctx.config.displayInlayHints; | 64 | this.enabled = ctx.config.displayInlayHints; |
65 | } | 65 | } |
66 | 66 | ||
67 | async setEnabled(enabled: boolean) { | 67 | async setEnabled(enabled: boolean): Promise<void> { |
68 | if (this.enabled == enabled) return; | 68 | if (this.enabled == enabled) return; |
69 | this.enabled = enabled; | 69 | this.enabled = enabled; |
70 | 70 | ||
71 | if (this.enabled) { | 71 | if (this.enabled) { |
72 | await this.refresh(); | 72 | return await this.refresh(); |
73 | } else { | ||
74 | this.allEditors.forEach(it => { | ||
75 | this.setTypeDecorations(it, []); | ||
76 | this.setParameterDecorations(it, []); | ||
77 | }); | ||
78 | } | 73 | } |
74 | this.allEditors.forEach(it => { | ||
75 | this.setTypeDecorations(it, []); | ||
76 | this.setParameterDecorations(it, []); | ||
77 | }); | ||
79 | } | 78 | } |
80 | 79 | ||
81 | async refresh() { | 80 | async refresh() { |
82 | if (!this.enabled) return; | 81 | if (!this.enabled) return; |
83 | const promises = this.allEditors.map(it => this.refreshEditor(it)); | 82 | await Promise.all(this.allEditors.map(it => this.refreshEditor(it))); |
84 | await Promise.all(promises); | 83 | } |
84 | |||
85 | private get allEditors(): vscode.TextEditor[] { | ||
86 | return vscode.window.visibleTextEditors.filter( | ||
87 | editor => editor.document.languageId === 'rust', | ||
88 | ); | ||
85 | } | 89 | } |
86 | 90 | ||
87 | private async refreshEditor(editor: vscode.TextEditor): Promise<void> { | 91 | private async refreshEditor(editor: vscode.TextEditor): Promise<void> { |
88 | const newHints = await this.queryHints(editor.document.uri.toString()); | 92 | const newHints = await this.queryHints(editor.document.uri.toString()); |
89 | if (newHints == null) return; | 93 | if (newHints == null) return; |
90 | const newTypeDecorations = newHints.filter(hint => hint.kind === 'TypeHint') | 94 | |
95 | const newTypeDecorations = newHints | ||
96 | .filter(hint => hint.kind === 'TypeHint') | ||
91 | .map(hint => ({ | 97 | .map(hint => ({ |
92 | range: hint.range, | 98 | range: hint.range, |
93 | renderOptions: { | 99 | renderOptions: { |
@@ -98,7 +104,8 @@ class HintsUpdater { | |||
98 | })); | 104 | })); |
99 | this.setTypeDecorations(editor, newTypeDecorations); | 105 | this.setTypeDecorations(editor, newTypeDecorations); |
100 | 106 | ||
101 | const newParameterDecorations = newHints.filter(hint => hint.kind === 'ParameterHint') | 107 | const newParameterDecorations = newHints |
108 | .filter(hint => hint.kind === 'ParameterHint') | ||
102 | .map(hint => ({ | 109 | .map(hint => ({ |
103 | range: hint.range, | 110 | range: hint.range, |
104 | renderOptions: { | 111 | renderOptions: { |
@@ -110,12 +117,6 @@ class HintsUpdater { | |||
110 | this.setParameterDecorations(editor, newParameterDecorations); | 117 | this.setParameterDecorations(editor, newParameterDecorations); |
111 | } | 118 | } |
112 | 119 | ||
113 | private get allEditors(): vscode.TextEditor[] { | ||
114 | return vscode.window.visibleTextEditors.filter( | ||
115 | editor => editor.document.languageId === 'rust', | ||
116 | ); | ||
117 | } | ||
118 | |||
119 | private setTypeDecorations( | 120 | private setTypeDecorations( |
120 | editor: vscode.TextEditor, | 121 | editor: vscode.TextEditor, |
121 | decorations: vscode.DecorationOptions[], | 122 | decorations: vscode.DecorationOptions[], |
@@ -139,12 +140,14 @@ class HintsUpdater { | |||
139 | private async queryHints(documentUri: string): Promise<InlayHint[] | null> { | 140 | private async queryHints(documentUri: string): Promise<InlayHint[] | null> { |
140 | const client = this.ctx.client; | 141 | const client = this.ctx.client; |
141 | if (!client) return null; | 142 | if (!client) return null; |
143 | |||
142 | const request: InlayHintsParams = { | 144 | const request: InlayHintsParams = { |
143 | textDocument: { uri: documentUri }, | 145 | textDocument: { uri: documentUri }, |
144 | }; | 146 | }; |
145 | const tokenSource = new vscode.CancellationTokenSource(); | 147 | const tokenSource = new vscode.CancellationTokenSource(); |
146 | const prev = this.pending.get(documentUri); | 148 | const prevHintsRequest = this.pending.get(documentUri); |
147 | if (prev) prev.cancel(); | 149 | prevHintsRequest?.cancel(); |
150 | |||
148 | this.pending.set(documentUri, tokenSource); | 151 | this.pending.set(documentUri, tokenSource); |
149 | try { | 152 | try { |
150 | return await sendRequestWithRetry<InlayHint[] | null>( | 153 | return await sendRequestWithRetry<InlayHint[] | null>( |