Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(picker): score bonus for file extension prefix match #787

Closed
1 task done
jdrouhard opened this issue Jan 29, 2025 · 5 comments · Fixed by #728
Closed
1 task done

feature(picker): score bonus for file extension prefix match #787

jdrouhard opened this issue Jan 29, 2025 · 5 comments · Fixed by #728
Labels
enhancement New feature or request

Comments

@jdrouhard
Copy link
Contributor

Did you check the docs?

  • I have read all the snacks.nvim docs

Is your feature request related to a problem? Please describe.

fzf assigns a score bonus for fully matched prefixes in the file extension, but it doesn't look like snacks.picker does this.

Example:

  1. mkdir example && cd example
  2. touch Foo.cpp Foo.hpp FooConfig.cpp
  3. :lua Snacks.picker.files() vs :FzfLua files
  4. type foocp

Compare the match. fzf matcher will select Foo.cpp since the "cp" is an exact prefix match of the extension. snacks selects FooConfig.cpp since the first "c" matches a longer prefix in the file name, but the last "p" is actually the second character of the extension.

Describe the solution you'd like

The behavior of fzf here is desirable. It lets me quickly type part of a file name and part of the extension I want and more than likely get the file I'm looking for. In my example, if I actually wanted the config file, I'd type "fooconfcp" or something, but I'd do it intentionally.

Describe alternatives you've considered

fzf

Additional context

No response

@jdrouhard jdrouhard added the enhancement New feature or request label Jan 29, 2025
@folke
Copy link
Owner

folke commented Jan 29, 2025

fzf doesn't give bonusses for file extensions.
The reason FooConfig gets a higher score is due to the match with camelcase, which gets a bonus.

But I think I should only award a camelcase bonus for patterns starting at a camel-case position.

Will look into it.

@folke
Copy link
Owner

folke commented Jan 29, 2025

Found the issue. I didn't account for gaps in calculating the prev character class for transition bonusses.

@jdrouhard
Copy link
Contributor Author

jdrouhard commented Jan 29, 2025

Thanks, that was fast! Though it doesn't quite work in all cases.

Add FooBar.cpp and FooBarConfig.cpp to the test dir, and then try to match it by typing "foobarcp" in the picker. It'll match "FooBarConfig.cpp" and not "FooBar.cpp" even though typing "foocp" will now correctly match "Foo.cpp".

@folke

@folke
Copy link
Owner

folke commented Jan 29, 2025

I made some additional changes to more align with fzf.
Let me know if you'd still see difference.

Snacks does also give bonusses for matches in the file name similar to zf, so that will always be different however.

@jdrouhard
Copy link
Contributor Author

@folke, you're a true legend. This is now working perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants