[clang-tools-extra] r272387 - [include-fixer] give users an option to show N more headers in case there are too many candidates.

Eric Liu via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 10 05:10:05 PDT 2016


Author: ioeric
Date: Fri Jun 10 07:09:33 2016
New Revision: 272387

URL: http://llvm.org/viewvc/llvm-project?rev=272387&view=rev
Log:
[include-fixer] give users an option to show N more headers in case there are too many candidates.

Summary: give users an option to show N more headers in case there are too many candidates.

Reviewers: bkramer

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D21181

Modified:
    clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.py

Modified: clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.py
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.py?rev=272387&r1=272386&r2=272387&view=diff
==============================================================================
--- clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.py (original)
+++ clang-tools-extra/trunk/include-fixer/tool/clang-include-fixer.py Fri Jun 10 07:09:33 2016
@@ -34,6 +34,11 @@ if vim.eval('exists("g:clang_include_fix
       1,
       vim.eval('g:clang_include_fixer_maximum_suggested_headers'))
 
+increment_num=5
+if vim.eval('exists("g:clang_include_fixer_increment_num")') == "1":
+  increment_num = max(
+      1,
+      vim.eval('g:clang_include_fixer_increment_num'))
 
 def GetUserSelection(message, headers, maximum_suggested_headers):
   eval_message = message + '\n'
@@ -41,7 +46,9 @@ def GetUserSelection(message, headers, m
     eval_message += "({0}). {1}\n".format(idx+1, header)
   eval_message += "Enter (q) to quit;"
   if maximum_suggested_headers < len(headers):
-    eval_message += " (a) to show all candidates.";
+    eval_message += " (m) to show {0} more candidates.".format(
+        min(increment_num, len(headers) - maximum_suggested_headers))
+
   eval_message += "\nSelect (default 1): "
   res = vim.eval("input('{0}')".format(eval_message))
   if res == '':
@@ -49,15 +56,19 @@ def GetUserSelection(message, headers, m
     idx = 1
   elif res == 'q':
     raise Exception('   Insertion cancelled...')
-  elif res == 'a' and maximum_suggested_headers < len(headers):
-    return GetUserSelection(message, headers, len(headers))
+  elif res == 'm':
+    return GetUserSelection(message,
+                            headers, maximum_suggested_headers + increment_num)
   else:
     try:
       idx = int(res)
       if idx <= 0 or idx > len(headers):
         raise Exception()
     except Exception:
-        raise Exception('   ERROR: Invalid option "{0}"...Abort!'.format(res))
+      # Show a new prompt on invalid option instead of aborting so that users
+      # don't need to wait for another include-fixer run.
+      print >> sys.stderr, "Invalid option:", res
+      return GetUserSelection(message, headers, maximum_suggested_headers)
   return headers[idx-1]
 
 def execute(command, text):




More information about the cfe-commits mailing list