Skip to content

fix: columnar_menu create_string with quoted suggestions #886

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

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.

@reubeno
Copy link

reubeno commented Mar 13, 2025

Just came here to say a huge thanks to @blindFS and @ysthakur for the change 👏 ! My project just got a report yesterday of a panic in the .split_at() call in ColumnarMenu, but unrelated to quotes. I see this change has .min() calls in just the right places to avoid walking past the end of the string -- and sure enough, that takes care of the issue we were seeing with completion suggestions shorter than the text-being-completed.

Can't wait for the fix to show up in the next official release! We're heavy (and happy!) users of reedline completion, so don't hestitate to let me know if y'all could ever use help with testing or fixes in this area.

sholderbach added a commit to sholderbach/nushell that referenced this pull request Mar 13, 2025
sholderbach added a commit to nushell/nushell that referenced this pull request Mar 13, 2025
sholderbach pushed a commit to nushell/nushell that referenced this pull request Mar 15, 2025
#15299)

# Description

Found inconsistent behaviors of `directory_completion` and
`file_completion`, #13951

nushell/reedline#886

Also there're failing cases with such file names/dir names `foo(`,
`foo{`, `foo[`.
I think it doesn't harm to be more conservative at adding quotes, even
if it might be unnecessary for paired names like `foo{}`.

# User-Facing Changes

# Tests + Formatting

Adjusted

# After Submitting
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.

3 participants