Adjust the priority of code actions #21000
Open
+20
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closed: #3903
Example:
Why choose reordering over adjusting the push order of CodeActions from the backend/frontend?
Initially, following the guidance in #3903, I attempted to adjust the push order in the backend but found it ineffective.
Then I tried reordering them after the push was complete, and noticed the final presentation seemed to be sorted in segments. For example, we could make
Qualifyrank higher thanImport, but it could never surpasssimilar name.I realized this was likely a frontend issue, and eventually located the relevant code here:
rust-analyzer/editors/code/src/client.ts
Lines 176 to 178 in d26e4b2
Based on the inserted logs, the issue is indeed determined by the frontend.
However, judging from the code logic, it doesn't seem possible to change the final presentation order by altering the processing sequence, so I decided to sort them after all processing was complete.
The order is based on matklad's idea, namely

ra diagnostic > ra assist > rustc diagnosticAs for the criteria for determining priority, it might not be perfectly precise, but
it works :)The frontend testing framework seems relatively basic; I'm not sure where to write tests or how to write them.