Skip to content

Fix fuzzy argument completion for resolved commands - #19347

Merged
fdncred merged 5 commits into
nushell:mainfrom
akasakariko:fix/fuzzy-argument-completion-19338
Nov 14, 2026
Merged

fdncred merged 5 commits into
nushell:mainfrom
akasakariko:fix/fuzzy-argument-completion-19338

Conversation

@akasakariko

@akasakariko akasakariko commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #19338

Prevent unrelated fuzzy command matches such as semver bump from hiding file arguments for mv and external aliases

Restrict subcommands to typed or resolved parent names while respecting completions.case_sensitive and Unicode case folding, so default prefix completion still offers str upcase and str uppercase for STR up

Use visible scope names for module aliases, falling back to active overlay declarations when hide only toggled visibility, so hidden targets keep their qualification while private module targets stay unresolved and cannot select unrelated top-level subcommands

Preserve mistyped command correction for unresolved bare heads such as sr upc, fod br and foot bar without letting corrections suppress file completion

Reuse editor_is_resolved to preserve executable names and its global PATH fallback when the current directory is unavailable

Release notes summary

Fixed fuzzy argument completion hiding files while preserving valid subcommands, case-insensitive matching, module and hidden-target aliases, and mistyped command correction

Tests

Verified locally on macOS ARM64 with Rust 1.97.1

Reproduced the mis-cased head, Unicode case folding, hidden ordinary/module/module-main alias, and private module command alias failures before applying the fixes

  • cargo test --locked --profile ci -p nu-cli --test tests -- command_argument_completions — 34 passed
  • cargo test --locked --profile ci -p nu-cli --test tests -- subcommand_head_case_sensitivity — 2 passed
  • CARGO_BUILD_JOBS=1 cargo test --locked --profile ci -p nu-cli --no-fail-fast — 200 unit and 311 integration tests passed, 2 existing ignored
  • CARGO_BUILD_JOBS=1 cargo nuclippy and CARGO_BUILD_JOBS=1 cargo nuclippy-tests — passed
  • CARGO_BUILD_JOBS=1 cargo check --locked --profile ci --no-default-features --bin nu — passed
  • cargo fmt --all --check, typos and git diff --check — passed

Linux and Windows validation is pending GitHub CI for the updated commit

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review overview

🟡 Changes recommended

mv <Tab> gets files again, but aliases of module commands lose their subcommands, and external commands still hit #19338.

Findings: 1 High severity · 1 Medium severity · 1 Low severity

Open (3)

Notes from my clanker, checked on ef53334. Built the branch and ran a probe test for each finding with fuzzy and prefix matching, on this branch and on main's completer.rs. Prefix results are the same on both. I also tried the find_decl_name change against the existing completion tests.

Comment thread crates/nu-cli/tests/completions/mod.rs Resolved
@fdncred

fdncred commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Was it intentional that fuzzy Tab no longer fixes a mistyped command name? main replaces the head with the closest command. This branch offers files only:

input main afca640
sr upc str upcase, str uppercase files only
fod br, with def "food bar" [] food bar files only
foot bar, with def "foo-test-command bar" [] foo-test-command bar files only

subcommand_vs_external_completer asserted the fod br case before this PR. If the change is intended, please mention it in the release notes.

@akasakariko

Copy link
Copy Markdown
Contributor Author

Sorry, this was not intentional, I will restore the mistyped command correction

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review overview

🟡 Changes recommended

The three threads from my first review stay fixed on 87b72f5, and sr upc, fod br and foot bar get their corrections again, the same as main. The later commits leave three new points: mis-cased heads under prefix matching, aliases of hidden commands, and a third copy of the executable check.

Findings: 1 High severity · 0 Medium severity · 2 Low severity

Open (3)

Notes from my clanker, checked on 87b72f5. Built the branch and a local merge with main 85db7f8, ran cargo test -p nu-cli on the merge (310 + 341 passed, 2 ignored), and ran 29 completion inputs under fuzzy and prefix through a test probe on the branch, the merge and main. Nothing was run on Windows.

Respect completion case sensitivity with Unicode-aware parent-head matching

Recover hidden alias target heads without losing module qualification

Reuse executable resolution and cover the reported completion regressions

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review overview

🟡 Changes recommended

The three threads from my last review are fixed on 4988514, and I've resolved them. STR up gets its subcommands under prefix again, aliases of hidden commands keep theirs, and completion now calls editor_is_resolved. The new fallback for hidden aliases also fires for an alias of a module's private command, where it offers unrelated subcommands instead of files.

Findings: 0 High severity · 0 Medium severity · 1 Low severity

Open (1)

Notes from my clanker, checked on 4988514. Built the branch and ran 18 new completion inputs under fuzzy and prefix through a test probe, on 4988514 and on 87b72f5's completion sources, plus the earlier probe. Tried the overlay lookup on 4988514, and cargo test -p nu-cli passes with it (200 + 313, 2 ignored, the probes included). CI is green on 4988514. Nothing was run on Windows.

Comment on lines +1508 to +1517
.or_else(|| {
// A hidden target still runs through its alias. Recover the original
// head, retaining module qualification instead of using signature.name.
let alias_id = working_set.find_decl(working_set.get_span_contents(call.head))?;
let alias = working_set.get_decl(alias_id).as_alias()?;
let Expr::Call(target) = &alias.wrapped_call.expr else {
return None;
};
Some(working_set.get_span_contents(target.head))
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low severity Alias of a private module command offers unrelated subcommands

The fallback reads the alias target's head as it was written inside the module, then looks for subcommands of that name in the caller's scope. When the target is one of the module's private commands, the name means something else out here.

On 4988514 with the fuzzy algorithm:

module m { def to [x?: string] {}; export alias t = to }
use m t
t <Tab>
# 87b72f50f: files
# 4988514b4: to csv, to json, to kdl, ... (14 `to` converters), no files

A top-level def "foo bar" [] next to an exported alias f = foo that points at a private foo does the same. f <Tab> offers foo bar and no files.

hide only flips a decl's visibility. Its name stays in the overlay's decls, and a module's private command never gets there. So looking call.decl_id up in the active overlays without the visibility check tells the two cases apart. I tried this in place of the alias-head fallback on 4988514. The three new hidden-alias tests pass, both cases above fall back to files, and cargo test -p nu-cli passes. It also covers an alias of an alias (alias g = foo; alias f = g; hide foo, then f b), which gets files with the alias-head version. It does send use m [f "foo bar"], where the alias comes in without its target, back to files, as on 87b72f5.

.or_else(|| {
    // `hide` only flips a decl's visibility, so its name stays in the overlay.
    // A module's private command was never added here and stays unresolved.
    fn registered(overlay: &OverlayFrame, decl_id: DeclId) -> Option<&[u8]> {
        overlay
            .decls
            .iter()
            .find(|(_, id)| **id == decl_id)
            .map(|(name, _)| name.as_slice())
    }
    let mut removed = vec![];
    for frame in working_set.delta.scope.iter().rev() {
        let found = frame
            .active_overlays(&mut removed)
            .rev()
            .find_map(|overlay| registered(overlay, call.decl_id));
        if found.is_some() {
            return found;
        }
    }
    working_set
        .permanent_state
        .active_overlays(&removed)
        .rev()
        .find_map(|overlay| registered(overlay, call.decl_id))
})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5daffef

Replaced the alias wrapped-call head fallback with an active-overlay declaration lookup without the visibility check, so hidden commands stay resolved while private module targets remain unresolved and fall back to files

Added fuzzy_private_module_alias_falls_back_to_files in command_argument_completions, which failed before the change and passes after it along with the existing hidden-alias regressions

Verified locally on macOS ARM64 (nu-cli: 200 unit and 311 integration tests passed, 2 existing ignored; cargo nuclippy, cargo nuclippy-tests, --no-default-features check, cargo fmt --all --check, typos and git diff --check passed); CI for the updated commit is pending

Search active overlays without visibility filtering when find_decl_name returns None, so hidden commands keep their scoped names while private module targets remain unresolved

Add a regression test for an alias pointing to a private module command
@fdncred fdncred added A:completions Issues related to tab completion notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Nov 14, 2026
@fdncred
fdncred merged commit 40c64ac into nushell:main Nov 14, 2026
14 checks passed
@fdncred

fdncred commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Thanks!

@github-actions github-actions Bot added this to the v0.118.0 milestone Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:completions Issues related to tab completion notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[REGRESSION] Weird completion behavior with fuzzy algorithm

2 participants