MI: extract command completion logic from complete_command()
authorJan Vrany <jan.vrany@fit.cvut.cz>
Fri, 17 May 2019 09:58:23 +0000 (10:58 +0100)
committerJan Vrany <jan.vrany@fit.cvut.cz>
Fri, 17 May 2019 09:58:23 +0000 (10:58 +0100)
Extract completion logic from CLI complete_command() into a new
helper function complete().

gdb/Changelog:

* completer.h (complete): New function.
* completer.c (complete): Likewise.
* cli/cli-cmds.c: (complete_command): Update to use new complete()
function defined in completer.h.

gdb/ChangeLog
gdb/cli/cli-cmds.c
gdb/completer.c
gdb/completer.h

index fd9f70141be8f9f32424b951930bad1e9286dcd5..f05cbb9f7cb3308189d0c451dcbb15b68d35d72e 100644 (file)
@@ -1,3 +1,10 @@
+2019-01-24  Jan Vrany  <jan.vrany@fit.cvut.cz>
+
+       * completer.h (complete): New function.
+       * completer.c (complete): Likewise.
+       * cli/cli-cmds.c: (complete_command): Update to use new complete()
+       function defined in completer.h.
+
 2019-05-17  Jan Vrany  <jan.vrany@fit.cvut.cz>
 
        * MAINTAINERS (Write After Approval): Add myself.
index 3d8e2387ff751e218e1f160ae22bca0425b56c68..332078b910fc0388fb09b0afbc333dd412b54341 100644 (file)
@@ -243,40 +243,13 @@ complete_command (const char *arg, int from_tty)
   if (arg == NULL)
     arg = "";
 
-  completion_tracker tracker_handle_brkchars;
-  completion_tracker tracker_handle_completions;
-  completion_tracker *tracker;
-
   int quote_char = '\0';
   const char *word;
 
-  try
-    {
-      word = completion_find_completion_word (tracker_handle_brkchars,
-                                             arg, &quote_char);
-
-      /* Completers that provide a custom word point in the
-        handle_brkchars phase also compute their completions then.
-        Completers that leave the completion word handling to readline
-        must be called twice.  */
-      if (tracker_handle_brkchars.use_custom_word_point ())
-       tracker = &tracker_handle_brkchars;
-      else
-       {
-         complete_line (tracker_handle_completions, word, arg, strlen (arg));
-         tracker = &tracker_handle_completions;
-       }
-    }
-  catch (const gdb_exception &ex)
-    {
-      return;
-    }
+  completion_result result = complete (arg, &word, &quote_char);
 
   std::string arg_prefix (arg, word - arg);
 
-  completion_result result
-    = tracker->build_completion_result (word, word - arg, strlen (arg));
-
   if (result.number_matches != 0)
     {
       if (result.number_matches == 1)
index 5d1decca1d1b0b9ad5fb5a2c6c2c86a36b63c797..cc2f80bc66e0247b761c46dbe5678eb40bd1030b 100644 (file)
@@ -1613,6 +1613,41 @@ make_completion_match_str (gdb::unique_xmalloc_ptr<char> &&match_name,
   return gdb::unique_xmalloc_ptr<char> (newobj);
 }
 
+/* See complete.h.  */
+
+completion_result
+complete (const char *line, char const **word, int *quote_char)
+{
+  completion_tracker tracker_handle_brkchars;
+  completion_tracker tracker_handle_completions;
+  completion_tracker *tracker;
+
+  try
+    {
+      *word = completion_find_completion_word (tracker_handle_brkchars,
+                                             line, quote_char);
+
+      /* Completers that provide a custom word point in the
+        handle_brkchars phase also compute their completions then.
+        Completers that leave the completion word handling to readline
+        must be called twice.  */
+      if (tracker_handle_brkchars.use_custom_word_point ())
+       tracker = &tracker_handle_brkchars;
+      else
+       {
+         complete_line (tracker_handle_completions, *word, line, strlen (line));
+         tracker = &tracker_handle_completions;
+       }
+    }
+  catch (const gdb_exception &ex)
+    {
+      return {};
+    }
+
+  return tracker->build_completion_result (*word, *word - line, strlen (line));
+}
+
+
 /* Generate completions all at once.  Does nothing if max_completions
    is 0.  If max_completions is non-negative, this will collect at
    most max_completions strings.
index 52f8d7dff4f5bf25401faf904be7b5bf73568e1c..38a0132ca4d137aa9965b9903d0e31809db4987d 100644 (file)
@@ -510,6 +510,13 @@ extern void complete_line (completion_tracker &tracker,
                           const char *line_buffer,
                           int point);
 
+/* Complete LINE and return completion results.  For completion purposes,
+   cursor position is assumed to be at the end of LINE.  WORD is set to
+   the end of word to complete.  QUOTE_CHAR is set to the opening quote
+   character if we found an unclosed quoted substring, '\0' otherwise.  */
+extern completion_result
+  complete (const char *line, char const **word, int *quote_char);
+
 /* Find the bounds of the word in TEXT for completion purposes, and
    return a pointer to the end of the word.  Calls the completion
    machinery for a handle_brkchars phase (using TRACKER) to figure out
This page took 0.031727 seconds and 4 git commands to generate.