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

fix: columnar_menu create_string with quoted suggestions #886

Merged
merged 3 commits into from
Mar 12, 2025

Conversation

blindFS
Copy link
Contributor

@blindFS blindFS commented Mar 12, 2025

This is a stopgap for nushell/nushell#12680, nushell/nushell#13951, nushell/nushell#13630, nushell/nushell#15302.

Fuzzy matching will need more care, and I think @ysthakur knows how to fix that.

nushell/nushell#13951 also exposes another bug in directory_completion, i.e. not doing quoting, which is handled properly in file_completion.

@ysthakur
Copy link
Member

Thanks, it'd be good to have at least a temporary fix for this bug. Could you also modify ide_completions? It has the same problem with split_at.

For fuzzy completions, you can iterate over the graphemes in every suggestion and highlight every grapheme that contains a character whose index is less than shortest_base.len(). I was working on a function to do that here. That one's more complicated than what you need to do because it takes a list of match indices rather than just highlight a prefix (the function's from #798).

@ysthakur ysthakur added the A-Completions Area: Tab completion and inline hint completions label Mar 12, 2025
@blindFS
Copy link
Contributor Author

blindFS commented Mar 12, 2025

@ysthakur Thanks for the reminder! That's interesting, because I was looking at #839 and thought only columnar_menu had the problem, and I also greped create_string in the repo.

It turns out that ide_menu already got the width -> len fix somewhere else and the function name is create_value_string, LoL.

@blindFS
Copy link
Contributor Author

blindFS commented Mar 12, 2025

For fuzzy completions, you can iterate over the graphemes in every suggestion and highlight every grapheme that contains a character whose index is less than shortest_base.len(). I was working on a function to do that here. That one's more complicated than what you need to do because it takes a list of match indices rather than just highlight a prefix (the function's from #798).

I was hoping for a systematic solution for both issues, I'm not sure if nucleo_matcher can directly return the matching indices while calculating the score so that we don't need some extra overhead here in reedline.

@ysthakur
Copy link
Member

ysthakur commented Mar 12, 2025

LGTM! At some point, I'd like to get rid of the code duplication, but that's for another PR.


Nucleo can indeed return the matched indices, it's just going to take a bit of redesigning to include that information in Suggestions. To clarify, I wasn't suggesting Reedline do the matching all over again.

@ysthakur ysthakur merged commit dfdb167 into nushell:main Mar 12, 2025
6 checks passed
@blindFS blindFS deleted the fix_quoted branch March 12, 2025 22:48
@blindFS
Copy link
Contributor Author

blindFS commented Mar 12, 2025

Nucleo can indeed return the matched indices, it's just going to take a bit of redesigning to include that information in Suggestions. To clarify, I wasn't suggesting Reedline do the matching all over again.

That was what in my mind, e.g. 1 more field matched_indices: Option<Vec<usize>>.

If specified, do the ansi decoration accordingly.
Fallback to the original split_at when it's None. In this way, we only need to provide that when 1. Fuzzy algo enabled, 2. Extra quote added. And the indices should be easier to compute where the suggestion item is created. What do you think?

@ysthakur
Copy link
Member

@blindFS Yeah, that's what #798 was going to do. However, maxomatic suggested allowing more customizability and suggested a Styler trait. I sort of abandoned that PR, but last time I was working on it, I found that the Styler trait was too complicated, and that it was easier to add a field to Suggestion allowing the completer more control over styling (more control than just match_indices). I'll update that linked PR with my findings as soon as I can get back to it.

@blindFS
Copy link
Contributor Author

blindFS commented Mar 12, 2025

@blindFS Yeah, that's what #798 was going to do. However, maxomatic suggested allowing more customizability and suggested a Styler trait. I sort of abandoned that PR, but last time I was working on it, I found that the Styler trait was too complicated, and that it was easier to add a field to Suggestion allowing the completer more control over styling (more control than just match_indices). I'll update that linked PR with my findings as soon as I can get back to it.

I see, I think we are on the exact same page here. Sorry I misunderstood what you're going to do because I just had a glance at the linked function code you gave me earlier and didn't follow the entire stream of #798. IMHO, extra styling options are nice, but if things get complicated, we shouldn't let that subtlety block this important bug fix, right?

@ysthakur
Copy link
Member

Yup, I have a PR up (#887) for finishing this bug fix for fuzzy matching too. After that panic's fixed, we can work on figuring out adding match indices to Suggestion somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Completions Area: Tab completion and inline hint completions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants