Skip to content

fix(completions): run a wrapped rest completer on flag-like tokens - #19130

Merged
fdncred merged 2 commits into
nushell:mainfrom
kronberger-droid:fix/wrapped-rest-completes-flag-tokens
Oct 1, 2026
Merged

fdncred merged 2 commits into
nushell:mainfrom
kronberger-droid:fix/wrapped-rest-completes-flag-tokens

Conversation

@kronberger-droid

Copy link
Copy Markdown
Contributor

Description

In a def --wrapped command, what --<Tab> never called the completer on ...args (#19097).
Both trailing_slot and resolve_argument_site classify any token starting with - as SiteKind::FlagName, which dispatches to flag-name completion only, even though a wrapped command binds an unknown --x to its rest parameter.
This is a regression from #18761: before it, only a bare - routed to flag completion, so --x on a wrapped command reached the rest completer, which took precedence over @complete as it does again now.

SiteKind::FlagName now carries the positional the token would bind to.
On a wrapped command whose positional declares a completer, the flag names are merged with that positional's completion, through the same complete_argument_value chain a plain positional takes.
site_completer resolves the same completer, so an @interactive one still runs inline.

An undeclared rest parameter keeps flag-name completion only, since its shape fallback would list files for every - typed.
place.kind stays flag-name.

User-facing changes (Release notes)

Fixed a regression since 0.115 where custom completers on a def --wrapped rest parameter were not called for arguments starting with -, so what --<Tab> only offered declared flags.

Additional notes

fixes #19097

@fdncred
fdncred merged commit 3100c9d into nushell:main Oct 1, 2026
15 checks passed
@github-actions github-actions Bot added this to the 1.0 milestone Oct 1, 2026
@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 Oct 1, 2026
@fdncred

fdncred commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Thanks for stepping in and putting this up

@kronberger-droid
kronberger-droid deleted the fix/wrapped-rest-completes-flag-tokens branch October 1, 2026 11:34
@cptpiepmatz cptpiepmatz modified the milestones: 1.0, v0.117.1, v0.116.1 Oct 4, 2026
fdncred added a commit that referenced this pull request Nov 16, 2026
…ent completer, and drop carapace duplicates (#19554)

## Description

Two problems with flag completion on externs that use `@complete
external`, such as the ones `generate completions` writes.

**An argument completer hid the external completer's flags.** Take an
extern with `...args: external_arg@"nu-complete git remotes"`. At `git
remote prune -<Tab>`, the argument completer answered (with remote
names), and since #19130 an answering argument completer overrides the
command-wide one. So flags that only the external completer knows, such
as `-n` from carapace, never showed up. Now, at a flag token, the
command-wide completer's flags are added to whatever the argument
completer answers. The command-wide completer still runs only once per
Tab, because the same result is also the argument completer's fallback.
Argument positions keep the existing contract, so `git remote prune
<Tab>` still lists only remotes. When either completer is
`@interactive`, the command-wide one runs only as the fallback. An
`@interactive` command-wide completer isn't the site's first completer.
An `@interactive` argument completer (a picker) runs without it, so
neither a pick nor a cancel gets the command-wide completer's flags
mixed in.

**carapace duplicated every declared flag.** carapace returns values
like `--limit ` with a trailing space, so that a space follows the flag.
The dedupe against declared flags compared values exactly, so `jj log
--li<Tab>` offered both `--limit` and `--limit `. A trailing space no
longer makes a value new.

## User-facing changes (Release notes)

- At a flag token, the flags that `@complete` or the external completer
lists now show up even when the argument's own completer answers.
Argument values still come from the argument's completer alone.
- Flags that carapace returns with a trailing space are no longer listed
a second time next to the declared flag.

## Additional notes
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.

No custom argument completion for def --wrapped when argument starts with --

3 participants