Skip to content

Commit 8cdc493

Browse files
committed
fix: tweak hover/tooltip links
1 parent 8f45146 commit 8cdc493

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/tools/rust-analyzer/editors/code/src/client.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -392,14 +392,18 @@ function isCodeActionWithoutEditsAndCommands(value: any): boolean {
392392
// to proxy around that. We store the last hover's reference command link
393393
// here, as only one hover can be active at a time, and we don't need to
394394
// keep a history of these.
395-
export let HOVER_REFERENCE_COMMAND: ra.CommandLink | undefined = undefined;
395+
export let HOVER_REFERENCE_COMMAND: ra.CommandLink[] = [];
396396

397397
function renderCommand(cmd: ra.CommandLink): string {
398-
HOVER_REFERENCE_COMMAND = cmd;
399-
return `[${cmd.title}](command:rust-analyzer.hoverRefCommandProxy '${cmd.tooltip}')`;
398+
HOVER_REFERENCE_COMMAND.push(cmd);
399+
return `[${cmd.title}](command:rust-analyzer.hoverRefCommandProxy?${
400+
HOVER_REFERENCE_COMMAND.length - 1
401+
} '${cmd.tooltip}')`;
400402
}
401403

402404
function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownString {
405+
// clean up the previous hover ref command
406+
HOVER_REFERENCE_COMMAND = [];
403407
const text = actions
404408
.map(
405409
(group) =>

src/tools/rust-analyzer/editors/code/src/commands.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1203,9 +1203,10 @@ export function newDebugConfig(ctx: CtxInit): Cmd {
12031203
}
12041204

12051205
export function hoverRefCommandProxy(_: Ctx): Cmd {
1206-
return async () => {
1207-
if (HOVER_REFERENCE_COMMAND) {
1208-
const { command, arguments: args = [] } = HOVER_REFERENCE_COMMAND;
1206+
return async (index: number) => {
1207+
const link = HOVER_REFERENCE_COMMAND[index];
1208+
if (link) {
1209+
const { command, arguments: args = [] } = link;
12091210
await vscode.commands.executeCommand(command, ...args);
12101211
}
12111212
};

0 commit comments

Comments
 (0)