r303670 - [GSoC] Shell autocompletion for clang
Yuka Takahashi via cfe-commits
cfe-commits at lists.llvm.org
Tue May 23 11:39:09 PDT 2017
Author: yamaguchi
Date: Tue May 23 13:39:08 2017
New Revision: 303670
URL: http://llvm.org/viewvc/llvm-project?rev=303670&view=rev
Log:
[GSoC] Shell autocompletion for clang
Summary:
This is a first patch for GSoC project, bash-completion for clang.
To use this on bash, please run `source clang/utils/bash-autocomplete.sh`.
bash-autocomplete.sh is code for bash-completion.
Simple flag completion and path completion is available in this patch.
Reviewers: teemperor, v.g.vassilev, ruiu, Bigcheese, efriedma
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D33237
Added:
cfe/trunk/test/Driver/autocomplete.c
cfe/trunk/utils/bash-autocomplete.sh
Modified:
cfe/trunk/CMakeLists.txt
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/Driver.cpp
Modified: cfe/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=303670&r1=303669&r2=303670&view=diff
==============================================================================
--- cfe/trunk/CMakeLists.txt (original)
+++ cfe/trunk/CMakeLists.txt Tue May 23 13:39:08 2017
@@ -359,6 +359,10 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
PATTERN "*.inc"
PATTERN "*.h"
)
+
+ install(PROGRAMS utils/bash-autocomplete.sh
+ DESTINATION share/clang
+ )
endif()
add_definitions( -D_GNU_SOURCE )
Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=303670&r1=303669&r2=303670&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue May 23 13:39:08 2017
@@ -469,6 +469,7 @@ def arch__errors__fatal : Flag<["-"], "a
def arch : Separate<["-"], "arch">, Flags<[DriverOption]>;
def arch__only : Separate<["-"], "arch_only">;
def a : Joined<["-"], "a">;
+def autocomplete : Joined<["--"], "autocomplete=">;
def bind__at__load : Flag<["-"], "bind_at_load">;
def bundle__loader : Separate<["-"], "bundle_loader">;
def bundle : Flag<["-"], "bundle">;
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=303670&r1=303669&r2=303670&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue May 23 13:39:08 2017
@@ -1216,6 +1216,13 @@ bool Driver::HandleImmediateArgs(const C
return false;
}
+ if (Arg *A = C.getArgs().getLastArg(options::OPT_autocomplete)) {
+ // Print out all options that start with a given argument. This is used for
+ // shell autocompletion.
+ llvm::outs() << llvm::join(Opts->findByPrefix(A->getValue()), " ") << '\n';
+ return false;
+ }
+
if (C.getArgs().hasArg(options::OPT_print_libgcc_file_name)) {
ToolChain::RuntimeLibType RLT = TC.GetRuntimeLibType(C.getArgs());
switch (RLT) {
Added: cfe/trunk/test/Driver/autocomplete.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/autocomplete.c?rev=303670&view=auto
==============================================================================
--- cfe/trunk/test/Driver/autocomplete.c (added)
+++ cfe/trunk/test/Driver/autocomplete.c Tue May 23 13:39:08 2017
@@ -0,0 +1,6 @@
+// RUN: %clang --autocomplete=-fsyn | FileCheck %s -check-prefix=FSYN
+// FSYN: -fsyntax-only
+// RUN: %clang --autocomplete=-s | FileCheck %s -check-prefix=STD
+// STD: -std={{.*}}-stdlib=
+// RUN: %clang --autocomplete=foo | not FileCheck %s -check-prefix=NONE
+// NONE: foo
Added: cfe/trunk/utils/bash-autocomplete.sh
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/bash-autocomplete.sh?rev=303670&view=auto
==============================================================================
--- cfe/trunk/utils/bash-autocomplete.sh (added)
+++ cfe/trunk/utils/bash-autocomplete.sh Tue May 23 13:39:08 2017
@@ -0,0 +1,14 @@
+# Please add "source /path/to/bash-autocomplete.sh" to your .bashrc to use this.
+_clang()
+{
+ local cur prev words cword flags
+ _init_completion -n : || return
+
+ flags=$( clang --autocomplete="$cur" )
+ if [[ "$flags" == "" || "$cur" == "" ]]; then
+ _filedir
+ else
+ COMPREPLY=( $( compgen -W "$flags" -- "$cur" ) )
+ fi
+}
+complete -F _clang clang
More information about the cfe-commits
mailing list