helix
helix copied to clipboard
feat: menu sort strategy for fuzzy match score sorting in completion …
This adds a sorting strategy to the menu.
As of now, all completions are sorted alphabetically after passing the fuzzy match filter. With this PR they are sorted by their fuzzy match score after passing the filter. Code actions menu's behavior remains the same.
This comes from #2705, where it is needed for LSP preselect.
The diff may seem big because of the rustmft formatting that changed the indentation of a whole closure, but the only changes are:
- a new enum
- a new argument to the
Menu
constructor - a match on the enum in the
score()
method
This would fix https://github.com/helix-editor/helix/issues/2508
I don't think this fixes #2508. I tried it against the reproduction case there and the results are the same.
Are you sure ? I just tried the reproduction case in #2508 and this seems to solve the issue for me.
Whoops I was on the wrong branch 😅
Yep, looks like this does fix #2508 👍
Just rebased this on master, could someone review this pretty please ? It would unblock some PRs, including the LSP preselect feature that I implemented a couple months ago.
As a reminder: the diff may seem big because of the rustmft formatting that changed the indentation of a whole closure, but the only changes are:
- a new enum
- a new argument to the
Menu
constructor - a match on the enum in the
score()
method
Do we need the two strategies though? Why not just change the behaviour to sort based on the score?
Some pickers such as code actions do not use a score AFAIK, so it makes sense for them to be sorted alphabetically (which they are on master).
Looks like this is blocking https://github.com/helix-editor/helix/issues/3084#issuecomment-1200871015
To review I've used ?w=1
on the URL which ignores whitespace changes.
I still think this could be a method on the Item
trait? Something that returns Ord
and pattern
and score
would be one of the inputs. That way different menus could have their own sort strategies rather than hardcoding it to two.
Some pickers such as code actions do not use a score AFAIK, so it makes sense for them to be sorted alphabetically (which they are on master).
#4134 does change the strategy to sort by score too. So maybe #4134 is enough, then #2705 can be implemented on top of https://github.com/helix-editor/helix/pull/4134/commits/63a54ee19b522cb0b085f1da0f3dfe07174179d5
Superseeded by #4134 .