aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/inlay_hints.ts
diff options
context:
space:
mode:
Diffstat (limited to 'editors/code/src/inlay_hints.ts')
-rw-r--r--editors/code/src/inlay_hints.ts31
1 files changed, 8 insertions, 23 deletions
diff --git a/editors/code/src/inlay_hints.ts b/editors/code/src/inlay_hints.ts
index 5f9229efb..5951cf1b4 100644
--- a/editors/code/src/inlay_hints.ts
+++ b/editors/code/src/inlay_hints.ts
@@ -1,5 +1,5 @@
1import * as vscode from 'vscode'; 1import * as vscode from 'vscode';
2import * as lc from 'vscode-languageclient'; 2import * as ra from './rust-analyzer-api';
3 3
4import { Ctx } from './ctx'; 4import { Ctx } from './ctx';
5import { log, sendRequestWithRetry } from './util'; 5import { log, sendRequestWithRetry } from './util';
@@ -39,16 +39,6 @@ export function activateInlayHints(ctx: Ctx) {
39 void hintsUpdater.setEnabled(ctx.config.displayInlayHints); 39 void hintsUpdater.setEnabled(ctx.config.displayInlayHints);
40} 40}
41 41
42interface InlayHintsParams {
43 textDocument: lc.TextDocumentIdentifier;
44}
45
46interface InlayHint {
47 range: vscode.Range;
48 kind: "TypeHint" | "ParameterHint";
49 label: string;
50}
51
52const typeHintDecorationType = vscode.window.createTextEditorDecorationType({ 42const typeHintDecorationType = vscode.window.createTextEditorDecorationType({
53 after: { 43 after: {
54 color: new vscode.ThemeColor('rust_analyzer.inlayHint'), 44 color: new vscode.ThemeColor('rust_analyzer.inlayHint'),
@@ -107,9 +97,9 @@ class HintsUpdater {
107 if (newHints == null) return; 97 if (newHints == null) return;
108 98
109 const newTypeDecorations = newHints 99 const newTypeDecorations = newHints
110 .filter(hint => hint.kind === 'TypeHint') 100 .filter(hint => hint.kind === ra.InlayKind.TypeHint)
111 .map(hint => ({ 101 .map(hint => ({
112 range: hint.range, 102 range: this.ctx.client.protocol2CodeConverter.asRange(hint.range),
113 renderOptions: { 103 renderOptions: {
114 after: { 104 after: {
115 contentText: `: ${hint.label}`, 105 contentText: `: ${hint.label}`,
@@ -119,9 +109,9 @@ class HintsUpdater {
119 this.setTypeDecorations(editor, newTypeDecorations); 109 this.setTypeDecorations(editor, newTypeDecorations);
120 110
121 const newParameterDecorations = newHints 111 const newParameterDecorations = newHints
122 .filter(hint => hint.kind === 'ParameterHint') 112 .filter(hint => hint.kind === ra.InlayKind.ParameterHint)
123 .map(hint => ({ 113 .map(hint => ({
124 range: hint.range, 114 range: this.ctx.client.protocol2CodeConverter.asRange(hint.range),
125 renderOptions: { 115 renderOptions: {
126 before: { 116 before: {
127 contentText: `${hint.label}: `, 117 contentText: `${hint.label}: `,
@@ -151,20 +141,15 @@ class HintsUpdater {
151 ); 141 );
152 } 142 }
153 143
154 private async queryHints(documentUri: string): Promise<InlayHint[] | null> { 144 private async queryHints(documentUri: string): Promise<ra.InlayHint[] | null> {
155 this.pending.get(documentUri)?.cancel(); 145 this.pending.get(documentUri)?.cancel();
156 146
157 const tokenSource = new vscode.CancellationTokenSource(); 147 const tokenSource = new vscode.CancellationTokenSource();
158 this.pending.set(documentUri, tokenSource); 148 this.pending.set(documentUri, tokenSource);
159 149
160 const request: InlayHintsParams = { textDocument: { uri: documentUri } }; 150 const request = { textDocument: { uri: documentUri } };
161 151
162 return sendRequestWithRetry<InlayHint[]>( 152 return sendRequestWithRetry(this.ctx.client, ra.inlayHints, request, tokenSource.token)
163 this.ctx.client,
164 'rust-analyzer/inlayHints',
165 request,
166 tokenSource.token
167 )
168 .catch(_ => null) 153 .catch(_ => null)
169 .finally(() => { 154 .finally(() => {
170 if (!tokenSource.token.isCancellationRequested) { 155 if (!tokenSource.token.isCancellationRequested) {