Skip to content

Commit 2073051

Browse files
authored
Preserve order of supplied zsh completion candidates. (#775)
Signed-off-by: Ross Goldberg <[email protected]>
1 parent fd0db17 commit 2073051

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension [ParsableCommand.Type] {
2323
\(completeFunctionName)() {
2424
local -ar non_empty_completions=("${@:#(|:*)}")
2525
local -ar empty_completions=("${(M)@:#(|:*)}")
26-
_describe '' non_empty_completions -- empty_completions -P $'\\'\\''
26+
_describe -V '' non_empty_completions -- empty_completions -P $'\\'\\''
2727
}
2828
2929
\(customCompleteFunctionName)() {
@@ -83,7 +83,7 @@ extension [ParsableCommand.Type] {
8383
.joined(separator: "\n")
8484
)
8585
)
86-
_describe "subcommand" subcommands
86+
_describe -V subcommand subcommands
8787
;;
8888
arg)
8989
case "${words[1]}" in
@@ -195,7 +195,7 @@ extension [ParsableCommand.Type] {
195195

196196
case .shellCommand(let command):
197197
return (
198-
"{local -a list;list=(${(f)\"$(\(command.shellEscapeForSingleQuotedString()))\"});_describe \"\" list}",
198+
"{local -a list;list=(${(f)\"$(\(command.shellEscapeForSingleQuotedString()))\"});_describe -V \"\" list}",
199199
nil
200200
)
201201

Tests/ArgumentParserExampleTests/Snapshots/testMathZshCompletionScript().zsh

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
__math_complete() {
44
local -ar non_empty_completions=("${@:#(|:*)}")
55
local -ar empty_completions=("${(M)@:#(|:*)}")
6-
_describe '' non_empty_completions -- empty_completions -P $'\'\''
6+
_describe -V '' non_empty_completions -- empty_completions -P $'\'\''
77
}
88

99
__math_custom_complete() {
@@ -55,7 +55,7 @@ _math() {
5555
'stats:Calculate descriptive statistics.'
5656
'help:Show subcommand help information.'
5757
)
58-
_describe "subcommand" subcommands
58+
_describe -V subcommand subcommands
5959
;;
6060
arg)
6161
case "${words[1]}" in
@@ -111,7 +111,7 @@ _math_stats() {
111111
'stdev:Print the standard deviation of the values.'
112112
'quantiles:Print the quantiles of the values (TBD).'
113113
)
114-
_describe "subcommand" subcommands
114+
_describe -V subcommand subcommands
115115
;;
116116
arg)
117117
case "${words[1]}" in
@@ -161,7 +161,7 @@ _math_stats_quantiles() {
161161
':values:'
162162
'--file:file:_files -g '\''*.txt *.md'\'''
163163
'--directory:directory:_files -/'
164-
'--shell:shell:{local -a list;list=(${(f)"$(head -100 /usr/share/dict/words | tail -50)"});_describe "" list}'
164+
'--shell:shell:{local -a list;list=(${(f)"$(head -100 /usr/share/dict/words | tail -50)"});_describe -V "" list}'
165165
'--custom:custom:{__math_custom_complete ---completion stats quantiles -- --custom "${current_word_index}" "$(__math_cursor_index_in_current_word)"}'
166166
'--custom-deprecated:custom-deprecated:{__math_custom_complete ---completion stats quantiles -- --custom-deprecated}'
167167
'--version[Show the version.]'

Tests/ArgumentParserUnitTests/Snapshots/testBase_Zsh().zsh

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
__base-test_complete() {
44
local -ar non_empty_completions=("${@:#(|:*)}")
55
local -ar empty_completions=("${(M)@:#(|:*)}")
6-
_describe '' non_empty_completions -- empty_completions -P $'\'\''
6+
_describe -V '' non_empty_completions -- empty_completions -P $'\'\''
77
}
88

99
__base-test_custom_complete() {
@@ -70,7 +70,7 @@ _base-test() {
7070
'escaped-command:'
7171
'help:Show subcommand help information.'
7272
)
73-
_describe "subcommand" subcommands
73+
_describe -V subcommand subcommands
7474
;;
7575
arg)
7676
case "${words[1]}" in

0 commit comments

Comments
 (0)