helix icon indicating copy to clipboard operation
helix copied to clipboard

Improve sorting for inline menu (codeaction + completion)

Open pascalkuthe opened this issue 3 years ago • 0 comments

Code actions are currently sorted alphabetically because they simply reuse the Menu used for autocompletions. This is extremely inconvenient in many cases. For example rust-analyzer emits a ton of (sometimes useful) refactors code-actions that get sorted before the quick fix (import ...) I am interested in.

This PR improves upon this in two ways:

The simplest fix is simply not sorting code actions in the Menu. However many LSP implementations send their code actions unordered because they assume that the client will sort the code actions by the kind field.

VScode uses 8 cateogoris for code actions:

  • quickfix
  • refactor (extract)
  • refactor (inline)
  • refactor (rewrite)
  • refactor (move)
  • refactor (surround)
  • source
  • anything else

I have opted to match this behavior by sorting the code actions into these categories. Note that I was careful to retain the original sorting by the server within these categories.

This is a huge usability improvement for people that frequently use codeactions. Example from the helix sourcecode where an import is missing:

before: image

after: image

Edit: This PR was originally just about code-actions, however I found #3215 and noticed that the changes there are sort of the same as in this PR: both PRs needed to handle code-actions separately from auto-completion sorting, #3215 sorted the code-actions alphabetically while this PR sorts them by category. Enabling fuzzy sorting for auto completions on top this PR is a single-line change and I have therefore opted to include it in this PR. I can drop the commit again and spin that out into a separate PR if this is controversial. The change is trivial and it made sense to me to include it here. fixes #2508

pascalkuthe avatar Oct 06 '22 23:10 pascalkuthe