nushell icon indicating copy to clipboard operation
nushell copied to clipboard

There *must* be a way to disable this fuzzy completion behavior.

Open colemickens opened this issue 1 year ago • 10 comments

Related problem

This has caused problems for me. I apologize for the tone - but this is a full-stop deal-breaker for me using nushell.

screenshot-1719017165 screenshot-1719014808

I cannot have my shell suggesting completions that ignore what I have typed in, or think it knows better than me.

Describe the solution you'd like

Don't do this. Certainly don't do it when completions.algorithm = prefix.

Or restore whatever option used to govern this. Because I've hit this in the past, and it either regressed or I can't find the right option in the stock config to override.

Describe alternatives you've considered

No.

Additional context and details

This is on rev c09488f51580ac4208e300b27365ff3c4095ba4a.

It seems like behavior like this was:

  • removed in: https://github.com/nushell/nushell/pull/10588
  • possibly re-introduced in : https://github.com/nushell/nushell/pull/10543

colemickens avatar Jun 22 '24 01:06 colemickens

Thanks for bringing this to our attention. As far as I can tell, those aren't fuzzy completions. The problem is that each segment of the path you've typed in is separately matched. So Nushell will begin by looking for folders matching the prefix code, and it finds code and code_old and starts looking inside those.

I can see how this can be undesirable behavior, but may I ask why it's a deal-breaker? As far as I can tell, all the completions inside ~/code/ show up before the undesired completions inside ~/code_old/.

Anyone have opinions on whether we should make a new config option for more strict matching, change the existing behavior, or something else? I personally am against changing the existing prefix matching behavior, since it seems like people liked https://github.com/nushell/nushell/pull/10543, and I personally ocassionally use it too.

ysthakur avatar Jun 22 '24 01:06 ysthakur

This is why. The "right" suggestion is not first.

╭ zeph  ~  0sec  ✘1
╰🡒 | cd code/fla<tab>
code-git/flake-firefox-nightly-fork/
code/flake-firefox-nightly-fork/

Even worse, I have code-git/u-boot but not code/u-boot and typing code/u-boot<tab> coerces it to code-old. Sometimes without me even noticing.

colemickens avatar Jun 22 '24 01:06 colemickens

Ah, I see. That's an issue even if someone's happy with Fish-like completions. We need to fix how completions are sorted. Would you be willing to make a PR?

ysthakur avatar Jun 22 '24 01:06 ysthakur

I actually have a barely-breathing PR (https://github.com/nushell/nushell/pull/12977) that I think would solve this. The problem is that currently, all the completions are fetched, and then they're sorted, meaning that when "code-git/..." is compared to "code/...", the former comes first because '-' > '/'. I'm pretty sure my PR sorts within each directory (or at least makes it easy to do so), which would fix this issue. But it's not going to be merged, at least not anytime soon, so anyone else is free to jump in and adapt my PR (or make an entirely fresh one) to fix this issue in the meantime.

ysthakur avatar Jun 22 '24 01:06 ysthakur

(I can't commit to digging into this right now, it'd be fun, just got a million other more pressing things, sorry!) Thanks to those triaging/developing. <3.

colemickens avatar Jun 22 '24 02:06 colemickens

Now that we know what the real issue is, could you update your issue title to "Change sort order for nested directory completions" (or something more descriptive like that)? That will save folks the time of reading through the thread in order to figure out the real request.

NotTheDr01ds avatar Jun 22 '24 12:06 NotTheDr01ds

No, I don't want it doing this, regardless of sort order. I never, ever want completions that don't match what I've typed.

colemickens avatar Jun 22 '24 20:06 colemickens

@fdncred did you end up changing the sort order from lev distance? That might have had some impact on this

I do think it would be a good idea also to have this sort of path-based prefixing configurable, because I've had some tests fail on nushell if the parent directory contains another copy of nushell (e.g. nushell_2). The completion tests aren't expecting that and don't function correctly.

devyn avatar Jun 24 '24 22:06 devyn

@devyn File and directory completions are indeed not using Levenshtein distance, but I don't think that was it. I think it was merely a matter of sorting each directory's children before the completions were put together rather than sorting all the completions at the end while treating them as strings. https://github.com/nushell/nushell/pull/13242 seems to fix it (fingers crossed)

ysthakur avatar Jun 27 '24 02:06 ysthakur

@fdncred did you end up changing the sort order from lev distance?

I never changed it. I still want to though.

fdncred avatar Jun 27 '24 12:06 fdncred

@colemickens Does the solution in https://github.com/nushell/nushell/pull/13302 work for you?

ysthakur avatar Jul 07 '24 14:07 ysthakur

Any input @colemickens?

fdncred avatar Jul 16 '24 12:07 fdncred