diff options
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | include/clang/Driver/Options.td | 1 | ||||
-rw-r--r-- | lib/Driver/Driver.cpp | 7 | ||||
-rw-r--r-- | test/Driver/autocomplete.c | 6 | ||||
-rw-r--r-- | utils/bash-autocomplete.sh | 14 |
5 files changed, 32 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e43a103b2..c163a2b504 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ) diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index d812bd8ec0..4f1ea08dfe 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -469,6 +469,7 @@ def arch__errors__fatal : Flag<["-"], "arch_errors_fatal">; 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">; diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index f36deff5d7..bec4bf4928 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -1216,6 +1216,13 @@ bool Driver::HandleImmediateArgs(const Compilation &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) { diff --git a/test/Driver/autocomplete.c b/test/Driver/autocomplete.c new file mode 100644 index 0000000000..94649f2437 --- /dev/null +++ b/test/Driver/autocomplete.c @@ -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 diff --git a/utils/bash-autocomplete.sh b/utils/bash-autocomplete.sh new file mode 100644 index 0000000000..a906712514 --- /dev/null +++ b/utils/bash-autocomplete.sh @@ -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 |