fix: tweak hover/tooltip links

This commit is contained in:
Young-Flash 2024-07-26 23:10:20 +08:00
parent f46af90ba8
commit 38817263e4
2 changed files with 11 additions and 6 deletions

View file

@ -392,14 +392,18 @@ function isCodeActionWithoutEditsAndCommands(value: any): boolean {
// to proxy around that. We store the last hover's reference command link // to proxy around that. We store the last hover's reference command link
// here, as only one hover can be active at a time, and we don't need to // here, as only one hover can be active at a time, and we don't need to
// keep a history of these. // keep a history of these.
export let HOVER_REFERENCE_COMMAND: ra.CommandLink | undefined = undefined; export let HOVER_REFERENCE_COMMAND: ra.CommandLink[] = [];
function renderCommand(cmd: ra.CommandLink): string { function renderCommand(cmd: ra.CommandLink): string {
HOVER_REFERENCE_COMMAND = cmd; HOVER_REFERENCE_COMMAND.push(cmd);
return `[${cmd.title}](command:rust-analyzer.hoverRefCommandProxy '${cmd.tooltip}')`; return `[${cmd.title}](command:rust-analyzer.hoverRefCommandProxy?${
HOVER_REFERENCE_COMMAND.length - 1
} '${cmd.tooltip}')`;
} }
function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownString { function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownString {
// clean up the previous hover ref command
HOVER_REFERENCE_COMMAND = [];
const text = actions const text = actions
.map( .map(
(group) => (group) =>

View file

@ -1203,9 +1203,10 @@ export function newDebugConfig(ctx: CtxInit): Cmd {
} }
export function hoverRefCommandProxy(_: Ctx): Cmd { export function hoverRefCommandProxy(_: Ctx): Cmd {
return async () => { return async (index: number) => {
if (HOVER_REFERENCE_COMMAND) { const link = HOVER_REFERENCE_COMMAND[index];
const { command, arguments: args = [] } = HOVER_REFERENCE_COMMAND; if (link) {
const { command, arguments: args = [] } = link;
await vscode.commands.executeCommand(command, ...args); await vscode.commands.executeCommand(command, ...args);
} }
}; };