Skip to content

Commit fdc6df6

Browse files
max-sixtyclaude
andauthored
fix(nushell): switch wrapper to @complete attribute on untyped rest (#2458)
Per fdncred's recommendation in nushell/nushell#18128, replaces the parameter-level `[...args: string@\"nu-complete wt\"]` with a function-level `@complete` attribute on an untyped `[...args]` rest. The completer signature moves from `[context: string]` (with manual `split row \" \"` reconstruction) to `[spans: list<string>]`, which nushell pre-tokenizes — net deletion of seven lines of fragile token reassembly. Untyped rest is the form nushell routes through its normal external-argument handling, so once nushell/nushell#18131 ships in stable nu the wrapper will automatically benefit from `--flag=\"value\"` quote stripping and `~` expansion without further changes. Until then `--flag=\"value\"` still arrives at the binary with literal quotes — a pre-existing bug, not a regression introduced here. Supersedes #2437 (the body-level regex strip workaround). ## Test plan - [x] `cargo test --test integration --features shell-integration-tests` — 1717 passed (including all four nu wrapper cases) - [x] `pre-commit run --all-files` — clean - [x] Smoke-tested the rendered template parses cleanly under nu 0.112.1 - [ ] Hand-verify subcommand completion at trailing space (e.g. `wt switch <TAB>`) in an interactive nu session — couldn't drive reedline via PTY in test, but fdncred's example in nushell/nushell#18128 implies `spans` is populated at the cursor position Ref nushell/nushell#18128, nushell/nushell#18131 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 53fd613 commit fdc6df6

2 files changed

Lines changed: 22 additions & 20 deletions

File tree

src/shell/snapshots/worktrunk__shell__tests__init_nu.snap

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ expression: output
88
# Note: nushell's completion engine bypasses custom completers when the current
99
# token starts with `-`, so flag completions (e.g. `wt switch --<TAB>`) don't
1010
# appear. Subcommand and value completions work. (nushell/nushell#14504)
11-
export def "nu-complete wt" [context: string] {
11+
export def "nu-complete wt" [spans: list<string>] {
1212
let worktrunk_bin = if ($env.WORKTRUNK_BIN? | is-not-empty) {
1313
$env.WORKTRUNK_BIN
1414
} else {
@@ -17,15 +17,8 @@ export def "nu-complete wt" [context: string] {
1717
($external | get 0.path)
1818
}
1919
20-
let tokens = ($context | split row " " | where {|t| $t != "" })
21-
let tokens = if ($context | str ends-with " ") {
22-
$tokens | append ""
23-
} else {
24-
$tokens
25-
}
26-
2720
let result = (do {
28-
with-env { COMPLETE: nu } { ^$worktrunk_bin -- ...$tokens }
21+
with-env { COMPLETE: nu } { ^$worktrunk_bin -- ...$spans }
2922
} | complete)
3023
if $result.exit_code != 0 { return [] }
3124
@@ -66,7 +59,15 @@ export def "nu-complete wt" [context: string] {
6659
# Stderr flows to the terminal in real-time. The binary sees non-TTY stdout
6760
# and uses buffered mode, but commands other than `list` don't benefit from
6861
# progressive rendering anyway.
69-
export def --env --wrapped wt [...args: string@"nu-complete wt"] {
62+
#
63+
# Completer wired via `@complete` attribute on an untyped `[...args]` rest.
64+
# The parameter-level `string@"completer"` form keeps tokens literal, which
65+
# blocks nushell's normal argument handling for `--flag="value"` (quote
66+
# stripping) and `~` (path expansion). Untyped rest gets that handling once
67+
# nushell/nushell#18131 ships in stable nu; until then `--flag="value"` still
68+
# arrives quoted. See nushell/nushell#18128 for upstream tracking.
69+
@complete "nu-complete wt"
70+
export def --env --wrapped wt [...args] {
7071
let worktrunk_bin = if ($env.WORKTRUNK_BIN? | is-not-empty) {
7172
$env.WORKTRUNK_BIN
7273
} else {

templates/nushell.nu

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Note: nushell's completion engine bypasses custom completers when the current
55
# token starts with `-`, so flag completions (e.g. `wt switch --<TAB>`) don't
66
# appear. Subcommand and value completions work. (nushell/nushell#14504)
7-
export def "nu-complete {{ cmd }}" [context: string] {
7+
export def "nu-complete {{ cmd }}" [spans: list<string>] {
88
let worktrunk_bin = if ($env.WORKTRUNK_BIN? | is-not-empty) {
99
$env.WORKTRUNK_BIN
1010
} else {
@@ -13,15 +13,8 @@ export def "nu-complete {{ cmd }}" [context: string] {
1313
($external | get 0.path)
1414
}
1515

16-
let tokens = ($context | split row " " | where {|t| $t != "" })
17-
let tokens = if ($context | str ends-with " ") {
18-
$tokens | append ""
19-
} else {
20-
$tokens
21-
}
22-
2316
let result = (do {
24-
with-env { COMPLETE: nu } { ^$worktrunk_bin -- ...$tokens }
17+
with-env { COMPLETE: nu } { ^$worktrunk_bin -- ...$spans }
2518
} | complete)
2619
if $result.exit_code != 0 { return [] }
2720

@@ -62,7 +55,15 @@ export def "nu-complete {{ cmd }}" [context: string] {
6255
# Stderr flows to the terminal in real-time. The binary sees non-TTY stdout
6356
# and uses buffered mode, but commands other than `list` don't benefit from
6457
# progressive rendering anyway.
65-
export def --env --wrapped {{ cmd }} [...args: string@"nu-complete {{ cmd }}"] {
58+
#
59+
# Completer wired via `@complete` attribute on an untyped `[...args]` rest.
60+
# The parameter-level `string@"completer"` form keeps tokens literal, which
61+
# blocks nushell's normal argument handling for `--flag="value"` (quote
62+
# stripping) and `~` (path expansion). Untyped rest gets that handling once
63+
# nushell/nushell#18131 ships in stable nu; until then `--flag="value"` still
64+
# arrives quoted. See nushell/nushell#18128 for upstream tracking.
65+
@complete "nu-complete {{ cmd }}"
66+
export def --env --wrapped {{ cmd }} [...args] {
6667
let worktrunk_bin = if ($env.WORKTRUNK_BIN? | is-not-empty) {
6768
$env.WORKTRUNK_BIN
6869
} else {

0 commit comments

Comments
 (0)