helix icon indicating copy to clipboard operation
helix copied to clipboard

feat: menu sort strategy for fuzzy match score sorting in completion …

Open lazytanuki opened this issue 2 years ago • 10 comments

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

lazytanuki avatar Jul 27 '22 11:07 lazytanuki

This would fix https://github.com/helix-editor/helix/issues/2508

ChrHorn avatar Jul 27 '22 16:07 ChrHorn

I don't think this fixes #2508. I tried it against the reproduction case there and the results are the same.

the-mikedavis avatar Jul 27 '22 17:07 the-mikedavis

Are you sure ? I just tried the reproduction case in #2508 and this seems to solve the issue for me. image

lazytanuki avatar Jul 27 '22 17:07 lazytanuki

Whoops I was on the wrong branch 😅

Yep, looks like this does fix #2508 👍

the-mikedavis avatar Jul 27 '22 17:07 the-mikedavis

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

lazytanuki avatar Sep 07 '22 18:09 lazytanuki

Do we need the two strategies though? Why not just change the behaviour to sort based on the score?

archseer avatar Sep 09 '22 08:09 archseer

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).

lazytanuki avatar Sep 10 '22 16:09 lazytanuki

Looks like this is blocking https://github.com/helix-editor/helix/issues/3084#issuecomment-1200871015

lukepighetti avatar Oct 10 '22 13:10 lukepighetti

image

lazytanuki avatar Oct 14 '22 19:10 lazytanuki

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

archseer avatar Oct 15 '22 10:10 archseer

Superseeded by #4134 .

lazytanuki avatar Oct 26 '22 21:10 lazytanuki