summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuka Takahashi <yukatkh@gmail.com>2018-10-24 08:24:16 +0000
committerYuka Takahashi <yukatkh@gmail.com>2018-10-24 08:24:16 +0000
commitdf9c7e3001377d6da7098fdd4fc5c54293620d37 (patch)
treea05d7b68a92c0a117f2e73c777bd2390992120d6
parent2a1b1d94b63cf37513fb71057f2eb9ef85d91fba (diff)
downloadbcm5719-llvm-df9c7e3001377d6da7098fdd4fc5c54293620d37.tar.gz
bcm5719-llvm-df9c7e3001377d6da7098fdd4fc5c54293620d37.zip
[bash-autocompletion] Fix bug when a flag ends with '='
There was a bug that when a flag ends with '=' and no value was suggested, clang autocompletes the flag itself. For example, in bash, it looked like this: ``` $ clang -fmodule-file=[tab] -> $clang -fmodule-file=-fmodule-file ``` This is not what we expect. We expect a file autocompletion when no value was found. With this patch, pressing tab suggests files in the current directory. Reviewers: teemperor, ruiu Subscribers: cfe-commits llvm-svn: 345121
-rw-r--r--clang/lib/Driver/Driver.cpp4
-rw-r--r--clang/test/Driver/autocomplete.c6
2 files changed, 9 insertions, 1 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index f890a1dcef3..583803de575 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1534,7 +1534,9 @@ void Driver::HandleAutocompletions(StringRef PassedFlags) const {
if (SuggestedCompletions.empty())
SuggestedCompletions = Opts->suggestValueCompletions(Cur, "");
- if (SuggestedCompletions.empty()) {
+ // When flag ends with '=' and there was no value completion, return empty
+ // string and fall back to the file autocompletion.
+ if (SuggestedCompletions.empty() && !Cur.endswith("=")) {
// If the flag is in the form of "--autocomplete=-foo",
// we were requested to print out all option names that start with "-foo".
// For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
diff --git a/clang/test/Driver/autocomplete.c b/clang/test/Driver/autocomplete.c
index 16f2edf0345..fccce87d8e9 100644
--- a/clang/test/Driver/autocomplete.c
+++ b/clang/test/Driver/autocomplete.c
@@ -115,3 +115,9 @@
// Check if they can autocomplete values with coron
// RUN: %clang --autocomplete=foo,bar,,,-fno-sanitize-coverage=,f | FileCheck %s -check-prefix=FNOSANICOVER-CORON
// FNOSANICOVER-CORON: func
+
+// Clang should return empty string when no value completion was found, which will fall back to file autocompletion
+// RUN: %clang --autocomplete=-fmodule-file= | FileCheck %s -check-prefix=MODULE_FILE_EQUAL
+// MODULE_FILE_EQUAL-NOT: -fmodule-file=
+// RUN: %clang --autocomplete=-fmodule-file | FileCheck %s -check-prefix=MODULE_FILE
+// MODULE_FILE: -fmodule-file=
OpenPOWER on IntegriCloud