Repository navigation
Fix fuzzy argument completion for resolved commands - #19347
Conversation
There was a problem hiding this comment.
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
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.
|
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:
|
|
Sorry, this was not intentional, I will restore the mistyped command correction |
There was a problem hiding this comment.
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
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
There was a problem hiding this comment.
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
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.
| .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)) | ||
| }) |
There was a problem hiding this comment.
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 filesA 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))
})There was a problem hiding this comment.
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
|
Thanks! |



Description
Fixes #19338
Prevent unrelated fuzzy command matches such as
semver bumpfrom hiding file arguments formvand external aliasesRestrict subcommands to typed or resolved parent names while respecting
completions.case_sensitiveand Unicode case folding, so default prefix completion still offersstr upcaseandstr uppercaseforSTR upUse visible scope names for module aliases, falling back to active overlay declarations when
hideonly toggled visibility, so hidden targets keep their qualification while private module targets stay unresolved and cannot select unrelated top-level subcommandsPreserve mistyped command correction for unresolved bare heads such as
sr upc,fod brandfoot barwithout letting corrections suppress file completionReuse
editor_is_resolvedto preserve executable names and its global PATH fallback when the current directory is unavailableRelease 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 passedcargo test --locked --profile ci -p nu-cli --test tests -- subcommand_head_case_sensitivity— 2 passedCARGO_BUILD_JOBS=1 cargo test --locked --profile ci -p nu-cli --no-fail-fast— 200 unit and 311 integration tests passed, 2 existing ignoredCARGO_BUILD_JOBS=1 cargo nuclippyandCARGO_BUILD_JOBS=1 cargo nuclippy-tests— passedCARGO_BUILD_JOBS=1 cargo check --locked --profile ci --no-default-features --bin nu— passedcargo fmt --all --check,typosandgit diff --check— passedLinux and Windows validation is pending GitHub CI for the updated commit