summaryrefslogtreecommitdiffstats
path: root/clang/lib/Driver
diff options
context:
space:
mode:
authorYuka Takahashi <yukatkh@gmail.com>2018-10-24 12:43:25 +0000
committerYuka Takahashi <yukatkh@gmail.com>2018-10-24 12:43:25 +0000
commit46106f5ebe1b10d2ebf161959617229bba108d6b (patch)
tree209e583f203aacb97d02f04b44d6c0eaf725b220 /clang/lib/Driver
parentad672ffb643c646ca7680c765342bd58252ecdbe (diff)
downloadbcm5719-llvm-46106f5ebe1b10d2ebf161959617229bba108d6b.tar.gz
bcm5719-llvm-46106f5ebe1b10d2ebf161959617229bba108d6b.zip
[autocompletion] Handle the space before pressing tab
Summary: Distinguish "--autocomplete=-someflag" and "--autocomplete=-someflag," because the latter indicates that the user put a space before pushing tab which should end up in a file completion. Differential Revision: https://reviews.llvm.org/D53639 llvm-svn: 345133
Diffstat (limited to 'clang/lib/Driver')
-rw-r--r--clang/lib/Driver/Driver.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 583803de575..453758196cf 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1508,6 +1508,11 @@ void Driver::HandleAutocompletions(StringRef PassedFlags) const {
unsigned short DisableFlags =
options::NoDriverOption | options::Unsupported | options::Ignored;
+ // Distinguish "--autocomplete=-someflag" and "--autocomplete=-someflag,"
+ // because the latter indicates that the user put space before pushing tab
+ // which should end up in a file completion.
+ const bool HasSpace = PassedFlags.endswith(",");
+
// Parse PassedFlags by "," as all the command-line flags are passed to this
// function separated by ","
StringRef TargetFlags = PassedFlags;
@@ -1534,6 +1539,16 @@ void Driver::HandleAutocompletions(StringRef PassedFlags) const {
if (SuggestedCompletions.empty())
SuggestedCompletions = Opts->suggestValueCompletions(Cur, "");
+ // If Flags were empty, it means the user typed `clang [tab]` where we should
+ // list all possible flags. If there was no value completion and the user
+ // pressed tab after a space, we should fall back to a file completion.
+ // We're printing a newline to be consistent with what we print at the end of
+ // this function.
+ if (SuggestedCompletions.empty() && HasSpace && !Flags.empty()) {
+ llvm::outs() << '\n';
+ return;
+ }
+
// 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("=")) {
OpenPOWER on IntegriCloud