From 5e8adb18f4838aa9b63503e35beb777733f25bf7 Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Fri, 4 Oct 2024 16:50:40 +0200 Subject: [PATCH] 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 --- src/complete.rs | 6 ++++++ tests/checks/complete-group-order.fish | 6 +++--- tests/pexpects/complete-group-order.py | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/complete.rs b/src/complete.rs index f2b2d6e78..a80408cca 100644 --- a/src/complete.rs +++ b/src/complete.rs @@ -480,6 +480,12 @@ fn natural_compare_completions(a: &Completion, b: &Completion) -> Ordering { // Both completions are from a source with the --keep-order flag. 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) } diff --git a/tests/checks/complete-group-order.fish b/tests/checks/complete-group-order.fish index 6bb9a7f95..07c90aca5 100644 --- a/tests/checks/complete-group-order.fish +++ b/tests/checks/complete-group-order.fish @@ -18,15 +18,15 @@ complete -c fooc -fa "kilo juliett lima" # Generate completions complete -C"fooc " -# CHECK: alpha -# CHECK: bravo # CHECK: india # CHECK: foxtrot # CHECK: hotel # CHECK: golf # CHECK: charlie -# CHECK: delta # CHECK: echo +# CHECK: alpha +# CHECK: bravo +# CHECK: delta # CHECK: juliett # CHECK: kilo # CHECK: lima diff --git a/tests/pexpects/complete-group-order.py b/tests/pexpects/complete-group-order.py index d1bc88258..82ea76b89 100644 --- a/tests/pexpects/complete-group-order.py +++ b/tests/pexpects/complete-group-order.py @@ -43,6 +43,6 @@ expect_prompt() send("fooc \t") expect_re( - "alpha\W+india\W+hotel\W+charlie\W+echo\W+kilo\r\n" - + "bravo\W+foxtrot\W+golf\W+delta\W+juliett\W+lima" + "india\W+hotel\W+charlie\W+alpha\W+delta\W+kilo\r\n" + + "foxtrot\W+golf\W+echo\W+bravo\W+juliett\W+lima" )