[PATCH] D35759: [Bash-autocompletion] Show HelpText with possible flags

Yuka Takahashi via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 21 20:21:46 PDT 2017


yamaguchi created this revision.
Herald added a subscriber: hiraditya.

`clang --autocomplete=-std` will show

  -std:   Language standard to compile for
  -std=   Language standard to compile for
  -stdlib=        C++ standard library to use

by this change.

However, showing HelpText with completion in bash seems super tricky, so
this feature will be used in other shells(fish, zsh...).


https://reviews.llvm.org/D35759

Files:
  clang/lib/Driver/Driver.cpp
  clang/utils/bash-autocomplete.sh
  llvm/lib/Option/OptTable.cpp


Index: llvm/lib/Option/OptTable.cpp
===================================================================
--- llvm/lib/Option/OptTable.cpp
+++ llvm/lib/Option/OptTable.cpp
@@ -237,7 +237,7 @@
     for (int I = 0; In.Prefixes[I]; I++) {
       std::string S = std::string(In.Prefixes[I]) + std::string(In.Name);
       if (StringRef(S).startswith(Cur))
-        Ret.push_back(S);
+        Ret.push_back(S + "\t" + std::string(StringRef(In.HelpText)));
     }
   }
   return Ret;
Index: clang/utils/bash-autocomplete.sh
===================================================================
--- clang/utils/bash-autocomplete.sh
+++ clang/utils/bash-autocomplete.sh
@@ -57,7 +57,7 @@
 
   # expand ~ to $HOME
   eval local path=${COMP_WORDS[0]}
-  flags=$( "$path" --autocomplete="$arg" 2>/dev/null )
+  flags=$( "$path" --autocomplete="$arg" 2>/dev/null | sed -e 's/\t.*//' )
   # If clang is old that it does not support --autocomplete,
   # fall back to the filename completion.
   if [[ "$?" != 0 ]]; then
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1299,7 +1299,7 @@
     std::sort(SuggestedCompletions.begin(), SuggestedCompletions.end(),
               [](StringRef A, StringRef B) { return A.compare_lower(B) < 0; });
 
-    llvm::outs() << llvm::join(SuggestedCompletions, " ") << '\n';
+    llvm::outs() << llvm::join(SuggestedCompletions, "\n") << '\n';
     return false;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35759.107773.patch
Type: text/x-patch
Size: 1510 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170722/34da2e4b/attachment.bin>


More information about the cfe-commits mailing list