dispose(): void;
}
export type Cmd = (...args: any[]) => unknown;
-
-export async function sendRequestWithRetry<R>(
- client: lc.LanguageClient,
- method: string,
- param: unknown,
- token?: vscode.CancellationToken,
-): Promise<R> {
- for (const delay of [2, 4, 6, 8, 10, null]) {
- try {
- return await (token ? client.sendRequest(method, param, token) : client.sendRequest(method, param));
- } catch (err) {
- if (delay === null || err.code !== lc.ErrorCodes.ContentModified) {
- throw err;
- }
- await sleep(10 * (1 << delay));
- }
- }
- throw 'unreachable';
-}
-
-const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
import { ColorTheme, TextMateRuleSettings } from './color_theme';
-import { Ctx, sendRequestWithRetry } from './ctx';
+import { Ctx } from './ctx';
+import { sendRequestWithRetry } from './util';
export function activateHighlighting(ctx: Ctx) {
const highlighter = new Highlighter(ctx);
import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient';
-import { Ctx, sendRequestWithRetry } from './ctx';
-import { log } from './util';
+import { Ctx } from './ctx';
+import { log, sendRequestWithRetry } from './util';
export function activateInlayHints(ctx: Ctx) {
const hintsUpdater = new HintsUpdater(ctx);
}
private async queryHints(documentUri: string): Promise<InlayHint[] | null> {
- const client = this.ctx.client;
- if (!client) return null;
+ this.pending.get(documentUri)?.cancel();
- const request: InlayHintsParams = {
- textDocument: { uri: documentUri },
- };
const tokenSource = new vscode.CancellationTokenSource();
- const prevHintsRequest = this.pending.get(documentUri);
- prevHintsRequest?.cancel();
-
this.pending.set(documentUri, tokenSource);
- try {
- return await sendRequestWithRetry<InlayHint[] | null>(
- client,
- 'rust-analyzer/inlayHints',
- request,
- tokenSource.token,
- );
- } finally {
- if (!tokenSource.token.isCancellationRequested) {
- this.pending.delete(documentUri);
- }
- }
+
+ const request: InlayHintsParams = { textDocument: { uri: documentUri } };
+
+ return sendRequestWithRetry<InlayHint[]>(
+ this.ctx.client,
+ 'rust-analyzer/inlayHints',
+ request,
+ tokenSource.token
+ )
+ .catch(_ => null)
+ .finally(() => {
+ if (!tokenSource.token.isCancellationRequested) {
+ this.pending.delete(documentUri);
+ }
+ });
}
}
+import * as lc from "vscode-languageclient";
+import * as vscode from "vscode";
+
let enabled: boolean = false;
export const log = {
enabled = yes;
}
};
+
+export async function sendRequestWithRetry<R>(
+ client: lc.LanguageClient,
+ method: string,
+ param: unknown,
+ token?: vscode.CancellationToken,
+): Promise<R> {
+ for (const delay of [2, 4, 6, 8, 10, null]) {
+ try {
+ return await (token
+ ? client.sendRequest(method, param, token)
+ : client.sendRequest(method, param)
+ );
+ } catch (error) {
+ if (delay === null) {
+ log.error("LSP request timed out", { method, param, error });
+ throw error;
+ }
+
+ if (error.code === lc.ErrorCodes.RequestCancelled) {
+ throw error;
+ }
+
+ if (error.code !== lc.ErrorCodes.ContentModified) {
+ log.error("LSP request failed", { method, param, error });
+ throw error;
+ }
+
+ await sleep(10 * (1 << delay));
+ }
+ }
+ throw 'unreachable';
+}
+
+function sleep(ms: number) {
+ return new Promise(resolve => setTimeout(resolve, ms));
+}