Skip to content

Commit 41428c1

Browse files
Adjust the priority of code actions
1 parent f3cbd0e commit 41428c1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

editors/code/src/client.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ export async function createClient(
260260
}
261261
result.push(primary);
262262
}
263+
264+
result.sort((a, b) => {
265+
const priorityA = getActionPriority(a);
266+
const priorityB = getActionPriority(b);
267+
return priorityA - priorityB;
268+
});
263269
return result;
264270
};
265271
return client
@@ -413,3 +419,17 @@ function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownStri
413419
result.isTrusted = true;
414420
return result;
415421
}
422+
423+
const getActionPriority = (action: vscode.CodeAction | vscode.Command): number => {
424+
// rust-analyzer diagnostic > rust-analyzer assist > rustc diagnostic > other
425+
if (!(action instanceof vscode.CodeAction)) {
426+
return 3;
427+
}
428+
429+
if (action.edit && action.edit.size > 0) return 2;
430+
const command = action.command?.command;
431+
if (command === "rust-analyzer.resolveCodeAction") return 0;
432+
if (command === "rust-analyzer.applyActionGroup") return 1;
433+
434+
return 3;
435+
};

0 commit comments

Comments
 (0)