mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
vscode: migrate inlay_hints to rust-analyzer-api.ts
This commit is contained in:
parent
8aea0ec511
commit
c9230b88b4
2 changed files with 16 additions and 31 deletions
|
@ -1,5 +1,5 @@
|
|||
import * as vscode from 'vscode';
|
||||
import * as lc from 'vscode-languageclient';
|
||||
import * as ra from './rust-analyzer-api';
|
||||
|
||||
import { Ctx } from './ctx';
|
||||
import { log, sendRequestWithRetry } from './util';
|
||||
|
@ -39,16 +39,6 @@ export function activateInlayHints(ctx: Ctx) {
|
|||
void hintsUpdater.setEnabled(ctx.config.displayInlayHints);
|
||||
}
|
||||
|
||||
interface InlayHintsParams {
|
||||
textDocument: lc.TextDocumentIdentifier;
|
||||
}
|
||||
|
||||
interface InlayHint {
|
||||
range: vscode.Range;
|
||||
kind: "TypeHint" | "ParameterHint";
|
||||
label: string;
|
||||
}
|
||||
|
||||
const typeHintDecorationType = vscode.window.createTextEditorDecorationType({
|
||||
after: {
|
||||
color: new vscode.ThemeColor('rust_analyzer.inlayHint'),
|
||||
|
@ -107,9 +97,9 @@ class HintsUpdater {
|
|||
if (newHints == null) return;
|
||||
|
||||
const newTypeDecorations = newHints
|
||||
.filter(hint => hint.kind === 'TypeHint')
|
||||
.filter(hint => hint.kind === ra.InlayKind.TypeHint)
|
||||
.map(hint => ({
|
||||
range: hint.range,
|
||||
range: this.ctx.client.protocol2CodeConverter.asRange(hint.range),
|
||||
renderOptions: {
|
||||
after: {
|
||||
contentText: `: ${hint.label}`,
|
||||
|
@ -119,9 +109,9 @@ class HintsUpdater {
|
|||
this.setTypeDecorations(editor, newTypeDecorations);
|
||||
|
||||
const newParameterDecorations = newHints
|
||||
.filter(hint => hint.kind === 'ParameterHint')
|
||||
.filter(hint => hint.kind === ra.InlayKind.ParameterHint)
|
||||
.map(hint => ({
|
||||
range: hint.range,
|
||||
range: this.ctx.client.protocol2CodeConverter.asRange(hint.range),
|
||||
renderOptions: {
|
||||
before: {
|
||||
contentText: `${hint.label}: `,
|
||||
|
@ -151,20 +141,15 @@ class HintsUpdater {
|
|||
);
|
||||
}
|
||||
|
||||
private async queryHints(documentUri: string): Promise<InlayHint[] | null> {
|
||||
private async queryHints(documentUri: string): Promise<ra.InlayHint[] | null> {
|
||||
this.pending.get(documentUri)?.cancel();
|
||||
|
||||
const tokenSource = new vscode.CancellationTokenSource();
|
||||
this.pending.set(documentUri, tokenSource);
|
||||
|
||||
const request: InlayHintsParams = { textDocument: { uri: documentUri } };
|
||||
const request = { textDocument: { uri: documentUri } };
|
||||
|
||||
return sendRequestWithRetry<InlayHint[]>(
|
||||
this.ctx.client,
|
||||
'rust-analyzer/inlayHints',
|
||||
request,
|
||||
tokenSource.token
|
||||
)
|
||||
return sendRequestWithRetry(this.ctx.client, ra.inlayHints, request, tokenSource.token)
|
||||
.catch(_ => null)
|
||||
.finally(() => {
|
||||
if (!tokenSource.token.isCancellationRequested) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue