complete: Sort --keep-order completions smaller

This should make the sort have a strict weak ordering, which rust
requires since 1.81 (or it will panic).

Note: This changes the order, but that's *fine* since the current
order is random weirdness anyway.

Fixes #10763
This commit is contained in:
Fabian Boehm 2024-10-04 16:50:40 +02:00
parent 2238c07b91
commit 5e8adb18f4
3 changed files with 11 additions and 5 deletions

View file

@ -480,6 +480,12 @@ fn natural_compare_completions(a: &Completion, b: &Completion) -> Ordering {
// Both completions are from a source with the --keep-order flag. // Both completions are from a source with the --keep-order flag.
return Ordering::Equal; return Ordering::Equal;
} }
if (a.flags).contains(CompleteFlags::DONT_SORT) {
return Ordering::Less;
}
if (b.flags).contains(CompleteFlags::DONT_SORT) {
return Ordering::Greater;
}
wcsfilecmp(&a.completion, &b.completion) wcsfilecmp(&a.completion, &b.completion)
} }

View file

@ -18,15 +18,15 @@ complete -c fooc -fa "kilo juliett lima"
# Generate completions # Generate completions
complete -C"fooc " complete -C"fooc "
# CHECK: alpha
# CHECK: bravo
# CHECK: india # CHECK: india
# CHECK: foxtrot # CHECK: foxtrot
# CHECK: hotel # CHECK: hotel
# CHECK: golf # CHECK: golf
# CHECK: charlie # CHECK: charlie
# CHECK: delta
# CHECK: echo # CHECK: echo
# CHECK: alpha
# CHECK: bravo
# CHECK: delta
# CHECK: juliett # CHECK: juliett
# CHECK: kilo # CHECK: kilo
# CHECK: lima # CHECK: lima

View file

@ -43,6 +43,6 @@ expect_prompt()
send("fooc \t") send("fooc \t")
expect_re( expect_re(
"alpha\W+india\W+hotel\W+charlie\W+echo\W+kilo\r\n" "india\W+hotel\W+charlie\W+alpha\W+delta\W+kilo\r\n"
+ "bravo\W+foxtrot\W+golf\W+delta\W+juliett\W+lima" + "foxtrot\W+golf\W+echo\W+bravo\W+juliett\W+lima"
) )