]> granicus.if.org Git - vim/commitdiff
patch 8.2.2992: Vim9: completion for :disassemble is incomplete v8.2.2992
authorBram Moolenaar <Bram@vim.org>
Sun, 13 Jun 2021 16:38:48 +0000 (18:38 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 13 Jun 2021 16:38:48 +0000 (18:38 +0200)
Problem:    Vim9: completion for :disassemble is incomplete.
Solution:   Recognize the "debug" and "profile" arguments.

src/cmdexpand.c
src/proto/vim9execute.pro
src/testdir/test_cmdline.vim
src/version.c
src/vim.h
src/vim9execute.c

index ba31e928c0dbc5c886b080cd8b7f24b85bd71122..9b6d9aa81d3c256b0c365149861a3e5abeb5b69d 100644 (file)
@@ -1557,10 +1557,12 @@ set_one_cmd_context(
 
        case CMD_function:
        case CMD_delfunction:
-       case CMD_disassemble:
            xp->xp_context = EXPAND_USER_FUNC;
            xp->xp_pattern = arg;
            break;
+       case CMD_disassemble:
+           set_context_in_disassemble_cmd(xp, arg);
+           break;
 
        case CMD_echohl:
            set_context_in_echohl_cmd(xp, arg);
@@ -2120,6 +2122,7 @@ ExpandFromContext(
            {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE},
            {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE},
            {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE},
+           {EXPAND_DISASSEMBLE, get_disassemble_argument, FALSE, TRUE},
            {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE},
 # endif
 # ifdef FEAT_MENU
index 4b6444a347a610c187266bb3875e5433cba99a3e..5712fcf76f36362ad99e4d3278dd70ec30b508e7 100644 (file)
@@ -7,6 +7,8 @@ int fill_partial_and_closure(partial_T *pt, ufunc_T *ufunc, ectx_T *ectx);
 int exe_typval_instr(typval_T *tv, typval_T *rettv);
 char_u *exe_substitute_instr(void);
 int call_def_function(ufunc_T *ufunc, int argc_arg, typval_T *argv, partial_T *partial, typval_T *rettv);
+void set_context_in_disassemble_cmd(expand_T *xp, char_u *arg);
+char_u *get_disassemble_argument(expand_T *xp, int idx);
 void ex_disassemble(exarg_T *eap);
 int tv2bool(typval_T *tv);
 void emsg_using_string_as(typval_T *tv, int as_number);
index a05d010d4409639ca098d80180e80401f7549764..90afe4516c0fde56ee919b1eac42fc118629c5db 100644 (file)
@@ -810,6 +810,16 @@ func Test_cmdline_complete_various()
   call feedkeys(":legac call strle\<C-A>\<C-B>\"\<CR>", 'xt')
   call assert_equal("\"legac call strlen(", @:)
 
+  " completion for the :disassemble command
+  call feedkeys(":disas deb\<C-A>\<C-B>\"\<CR>", 'xt')
+  call assert_equal("\"disas debug", @:)
+  call feedkeys(":disas pro\<C-A>\<C-B>\"\<CR>", 'xt')
+  call assert_equal("\"disas profile", @:)
+  call feedkeys(":disas debug Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
+  call assert_equal("\"disas debug Test_cmdline_complete_various", @:)
+  call feedkeys(":disas profile Test_cmdline_complete_var\<C-A>\<C-B>\"\<CR>", 'xt')
+  call assert_equal("\"disas profile Test_cmdline_complete_various", @:)
+
   " completion for the :match command
   call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
   call assert_equal("\"match Search /pat/\<C-A>", @:)
index 07c775b41b49965c025c083665f993a5581609df..441826b95b11cff1eefcd2ad68da863652fe276b 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2992,
 /**/
     2991,
 /**/
index 05af5a188283cf3a95d7b330e0be082a703c8e30..22fe8d5fed4f0bf02429d9e323daf23535733acc 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -777,6 +777,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
 #define EXPAND_MAPCLEAR                47
 #define EXPAND_ARGLIST         48
 #define EXPAND_DIFF_BUFFERS    49
+#define EXPAND_DISASSEMBLE     50
 
 // Values for exmode_active (0 is no exmode)
 #define EXMODE_NORMAL          1
index 04c1ee2f290d30cf69c319016084ad3275024a86..d55fa0c9d3aaf9c3694608e5016261c3a27908b0 100644 (file)
@@ -5370,6 +5370,40 @@ list_instructions(char *pfx, isn_T *instr, int instr_count, ufunc_T *ufunc)
     }
 }
 
+/*
+ * Handle command line completion for the :disassemble command.
+ */
+    void
+set_context_in_disassemble_cmd(expand_T *xp, char_u *arg)
+{
+    char_u     *p;
+
+    // Default: expand user functions, "debug" and "profile"
+    xp->xp_context = EXPAND_DISASSEMBLE;
+    xp->xp_pattern = arg;
+
+    // first argument already typed: only user function names
+    if (*arg != NUL && *(p = skiptowhite(arg)) != NUL)
+    {
+       xp->xp_context = EXPAND_USER_FUNC;
+       xp->xp_pattern = skipwhite(p);
+    }
+}
+
+/*
+ * Function given to ExpandGeneric() to obtain the list of :disassemble
+ * arguments.
+ */
+    char_u *
+get_disassemble_argument(expand_T *xp, int idx)
+{
+    if (idx == 0)
+       return (char_u *)"debug";
+    if (idx == 1)
+       return (char_u *)"profile";
+    return get_user_func_name(xp, idx - 2);
+}
+
 /*
  * ":disassemble".
  * We don't really need this at runtime, but we do have tests that require it,