about summary refs log tree commit diff
path: root/src/tools/rust-analyzer/editors/code
diff options
context:
space:
mode:
authorYoung-Flash <dongyang@apache.org>2024-07-26 23:10:20 +0800
committerYoung-Flash <dongyang@apache.org>2024-07-26 23:13:55 +0800
commit8cdc4932eeebfd4db2eb8abc572e5db1bde8b3cd (patch)
tree255546b1ac8898ea2b8bc09301934bdf57c70fc7 /src/tools/rust-analyzer/editors/code
parent8f45146ea51904379b3040928b990cbd8cbca5e6 (diff)
downloadrust-8cdc4932eeebfd4db2eb8abc572e5db1bde8b3cd.tar.gz
rust-8cdc4932eeebfd4db2eb8abc572e5db1bde8b3cd.zip
fix: tweak hover/tooltip links
Diffstat (limited to 'src/tools/rust-analyzer/editors/code')
-rw-r--r--src/tools/rust-analyzer/editors/code/src/client.ts10
-rw-r--r--src/tools/rust-analyzer/editors/code/src/commands.ts7
2 files changed, 11 insertions, 6 deletions
diff --git a/src/tools/rust-analyzer/editors/code/src/client.ts b/src/tools/rust-analyzer/editors/code/src/client.ts
index 357f131b93f..bf58112916b 100644
--- a/src/tools/rust-analyzer/editors/code/src/client.ts
+++ b/src/tools/rust-analyzer/editors/code/src/client.ts
@@ -392,14 +392,18 @@ function isCodeActionWithoutEditsAndCommands(value: any): boolean {
 // 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
 // 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 {
-    HOVER_REFERENCE_COMMAND = cmd;
-    return `[${cmd.title}](command:rust-analyzer.hoverRefCommandProxy '${cmd.tooltip}')`;
+    HOVER_REFERENCE_COMMAND.push(cmd);
+    return `[${cmd.title}](command:rust-analyzer.hoverRefCommandProxy?${
+        HOVER_REFERENCE_COMMAND.length - 1
+    } '${cmd.tooltip}')`;
 }
 
 function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownString {
+    // clean up the previous hover ref command
+    HOVER_REFERENCE_COMMAND = [];
     const text = actions
         .map(
             (group) =>
diff --git a/src/tools/rust-analyzer/editors/code/src/commands.ts b/src/tools/rust-analyzer/editors/code/src/commands.ts
index 621b9695786..773a4606014 100644
--- a/src/tools/rust-analyzer/editors/code/src/commands.ts
+++ b/src/tools/rust-analyzer/editors/code/src/commands.ts
@@ -1203,9 +1203,10 @@ export function newDebugConfig(ctx: CtxInit): Cmd {
 }
 
 export function hoverRefCommandProxy(_: Ctx): Cmd {
-    return async () => {
-        if (HOVER_REFERENCE_COMMAND) {
-            const { command, arguments: args = [] } = HOVER_REFERENCE_COMMAND;
+    return async (index: number) => {
+        const link = HOVER_REFERENCE_COMMAND[index];
+        if (link) {
+            const { command, arguments: args = [] } = link;
             await vscode.commands.executeCommand(command, ...args);
         }
     };