Commit 2fa4e6d
committed
fix(complete): fix bash dynamic-engine COMP_WORDBREAKS word reassembly
The bash glue script emitted by the dynamic completion engine
(CompleteEnv / write_registration in env/shells.rs) passes
words[COMP_CWORD]="$2" to the completer. Bash tokenizes COMP_WORDS by
splitting on COMP_WORDBREAKS characters (= and : by default), so
--option=value arrives as three tokens ("--option", "=", "value")
instead of one. This breaks completion for --option=value style
arguments.
Fix: embed a word reassembly loop (adapted from git-completion and
bash-completion's _comp__reassemble_words) that re-merges tokens split
on = and : before passing words to the Rust completer. The loop tracks
_CLAP_COMPLETE_INDEX in parallel so the completer receives the correct
position in the reassembled array.
The reassembly is gated on bash >= 4 (same condition as the original
block) and only affects = and : characters from COMP_WORDBREAKS, leaving
all other tokenization unchanged.
Snapshot updated accordingly.
Testing:
- cargo test -p clap_complete: 9 passed, 0 failed
- cargo test -p clap_complete --features clap_complete/unstable-dynamic:
109 passed, 0 failed
- Manual interactive test: sourced the generated completion script for
the exhaustive example and verified TAB-completion works correctly.
Fixes #63631 parent d142d8f commit 2fa4e6d
2 files changed
Lines changed: 52 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
43 | 68 | | |
44 | 69 | | |
45 | 70 | | |
| |||
Lines changed: 26 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
16 | 41 | | |
17 | 42 | | |
18 | 43 | | |
| |||
0 commit comments