]> granicus.if.org Git - clang/commitdiff
Sort the autocomplete candidates before printing them out.
authorRui Ueyama <ruiu@google.com>
Fri, 23 Jun 2017 15:37:52 +0000 (15:37 +0000)
committerRui Ueyama <ruiu@google.com>
Fri, 23 Jun 2017 15:37:52 +0000 (15:37 +0000)
Currently, autocompleted options are displayed in the same order as we
wrote them in .td files. This patch sort them out in clang so that they
are sorted alphabetically. This should improve usability.

Differential Revision: https://reviews.llvm.org/D34557

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306116 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Driver.cpp
test/Driver/autocomplete.c

index 850f6bc9dde71be77c2fee7b42d415114a7fb643..c8f389bfb0f76572242d7fb543ceadb112f7612c 100644 (file)
@@ -1245,6 +1245,13 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
       SuggestedCompletions = Opts->suggestValueCompletions(Option, Arg);
     }
 
+    // Sort the autocomplete candidates so that shells print them out in a
+    // deterministic order. We could sort in any way, but we chose
+    // case-insensitive sorting for consistency with the -help option
+    // which prints out options in the case-insensitive alphabetical order.
+    std::sort(SuggestedCompletions.begin(), SuggestedCompletions.end(),
+              [](StringRef A, StringRef B) { return A.compare_lower(B) < 0; });
+
     llvm::outs() << llvm::join(SuggestedCompletions, " ") << '\n';
     return false;
   }
index c7e339b616f1667b92a8dbb93a435c3082ba158b..117d7e9267d04ad96f7ffb186412df2abc4ec0cc 100644 (file)
@@ -11,7 +11,7 @@
 // RUN: %clang --autocomplete=-meabi,d | FileCheck %s -check-prefix=MEABI
 // MEABI: default
 // RUN: %clang --autocomplete=-meabi, | FileCheck %s -check-prefix=MEABIALL
-// MEABIALL: default 4 5 gnu
+// MEABIALL: 4 5 default gnu
 // RUN: %clang --autocomplete=-cl-std=,CL2 | FileCheck %s -check-prefix=CLSTD
 // CLSTD: CL2.0
 // RUN: %clang --autocomplete=-cl-std=, | FileCheck %s -check-prefix=CLSTDALL
 // RUN: %clang --autocomplete=-fno-sanitize-coverage=,f | FileCheck %s -check-prefix=FNOSANICOVER
 // FNOSANICOVER: func
 // RUN: %clang --autocomplete=-fno-sanitize-coverage=, | FileCheck %s -check-prefix=FNOSANICOVERALL
-// FNOSANICOVERALL: func bb edge indirect-calls trace-bb trace-cmp trace-div trace-gep 8bit-counters trace-pc trace-pc-guard no-prune inline-8bit-counters
+// FNOSANICOVERALL: 8bit-counters bb edge func indirect-calls inline-8bit-counters no-prune trace-bb trace-cmp trace-div trace-gep trace-pc trace-pc-guard
 // RUN: %clang --autocomplete=-ffp-contract=, | FileCheck %s -check-prefix=FFPALL
-// FFPALL: fast on off
+// FFPALL: fast off on
 // RUN: %clang --autocomplete=-flto=, | FileCheck %s -check-prefix=FLTOALL
-// FLTOALL: thin full
+// FLTOALL: full thin
 // RUN: %clang --autocomplete=-fveclib=, | FileCheck %s -check-prefix=FVECLIBALL
-// FVECLIBALL: Accelerate SVML none
+// FVECLIBALL: Accelerate none SVML
 // RUN: %clang --autocomplete=-fshow-overloads=, | FileCheck %s -check-prefix=FSOVERALL
-// FSOVERALL: best all
+// FSOVERALL: all best
 // RUN: %clang --autocomplete=-fvisibility=, | FileCheck %s -check-prefix=FVISIBILITYALL
-// FVISIBILITYALL: hidden default
+// FVISIBILITYALL: default hidden
 // RUN: %clang --autocomplete=-mfloat-abi=, | FileCheck %s -check-prefix=MFLOATABIALL
-// MFLOATABIALL: soft softfp hard
+// MFLOATABIALL: hard soft softfp
 // RUN: %clang --autocomplete=-mthread-model, | FileCheck %s -check-prefix=MTHREADMODELALL
 // MTHREADMODELALL: posix single