From 41428c156ec4852df8c253747dbf02d5bb579c0b Mon Sep 17 00:00:00 2001 From: Hegui Dai Date: Sat, 8 Nov 2025 15:10:58 +0800 Subject: [PATCH] Adjust the priority of code actions --- editors/code/src/client.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index cb71a01138b3..9654d740fa36 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -260,6 +260,12 @@ export async function createClient( } result.push(primary); } + + result.sort((a, b) => { + const priorityA = getActionPriority(a); + const priorityB = getActionPriority(b); + return priorityA - priorityB; + }); return result; }; return client @@ -413,3 +419,17 @@ function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownStri result.isTrusted = true; return result; } + +const getActionPriority = (action: vscode.CodeAction | vscode.Command): number => { + // rust-analyzer diagnostic > rust-analyzer assist > rustc diagnostic > other + if (!(action instanceof vscode.CodeAction)) { + return 3; + } + + if (action.edit && action.edit.size > 0) return 2; + const command = action.command?.command; + if (command === "rust-analyzer.resolveCodeAction") return 0; + if (command === "rust-analyzer.applyActionGroup") return 1; + + return 3; +};