[PATCH] D53639: [autocompletion] Handle the space before pressing tab
Yuka Takahashi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 24 04:07:15 PDT 2018
yamaguchi created this revision.
yamaguchi added reviewers: teemperor, ruiu.
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.
https://reviews.llvm.org/D53639
Files:
clang/lib/Driver/Driver.cpp
clang/test/Driver/autocomplete.c
Index: clang/test/Driver/autocomplete.c
===================================================================
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -121,3 +121,8 @@
// MODULE_FILE_EQUAL-NOT: -fmodule-file=
// RUN: %clang --autocomplete=-fmodule-file | FileCheck %s -check-prefix=MODULE_FILE
// MODULE_FILE: -fmodule-file=
+
+// RUN: %clang --autocomplete=-Qunused-arguments, | FileCheck %s -check-prefix=QUNUSED_COMMA
+// QUNUSED_COMMA-NOT: -Qunused-arguments
+// RUN: %clang --autocomplete=-Qunused-arguments | FileCheck %s -check-prefix=QUNUSED
+// QUNUSED: -Qunused-arguments
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1508,6 +1508,13 @@
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.
+ bool HasSpace = false;
+ if (PassedFlags.endswith(","))
+ HasSpace = true;
+
// Parse PassedFlags by "," as all the command-line flags are passed to this
// function separated by ","
StringRef TargetFlags = PassedFlags;
@@ -1525,6 +1532,14 @@
StringRef Cur;
Cur = Flags.at(Flags.size() - 1);
+
+ // If Flags were empty, it means the user typed `clang [tab]` where we should
+ // list all possible flags.
+ if (HasSpace && !Flags.empty()) {
+ llvm::outs() << '\n';
+ return;
+ }
+
StringRef Prev;
if (Flags.size() >= 2) {
Prev = Flags.at(Flags.size() - 2);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53639.170845.patch
Type: text/x-patch
Size: 1722 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181024/baa1184a/attachment.bin>
More information about the cfe-commits
mailing list