diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-01-15 06:40:49 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-01-15 07:59:45 +0800 |
commit | 064fdad98c6eed5f42b72eeeb3efe458fefb377d (patch) | |
tree | f5e7e5b7e0ec6e4e0a5da3b38f5d759ff06c0c54 | |
parent | f2056e4045a667447392f5e17c27b0f72ec7b8e0 (diff) | |
download | rneovim-064fdad98c6eed5f42b72eeeb3efe458fefb377d.tar.gz rneovim-064fdad98c6eed5f42b72eeeb3efe458fefb377d.tar.bz2 rneovim-064fdad98c6eed5f42b72eeeb3efe458fefb377d.zip |
vim-patch:8.2.4570: no command line completion for :profile and :profdel
Problem: No command line completion for :profile and :profdel.
Solution: Implement completion. (Yegappan Lakshmanan, closes vim/vim#9955)
https://github.com/vim/vim/commit/1fdf84e033f8c4eead3b4ccebb1969cfbc7d10db
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
-rw-r--r-- | src/nvim/cmdexpand.c | 22 | ||||
-rw-r--r-- | src/nvim/profile.c | 9 | ||||
-rw-r--r-- | src/nvim/testdir/test_cmdline.vim | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_profile.vim | 41 |
4 files changed, 63 insertions, 10 deletions
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 9d00851336..ca19d6de95 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -1659,8 +1659,9 @@ static const char *set_context_in_lang_cmd(expand_T *xp, const char *arg) } static enum { - EXP_BREAKPT_ADD, // expand ":breakadd" sub-commands - EXP_BREAKPT_DEL, // expand ":breakdel" sub-commands + EXP_BREAKPT_ADD, ///< expand ":breakadd" sub-commands + EXP_BREAKPT_DEL, ///< expand ":breakdel" sub-commands + EXP_PROFDEL, ///< expand ":profdel" sub-commands } breakpt_expand_what; /// Set the completion context for the :breakadd command. Always returns NULL. @@ -1671,8 +1672,10 @@ static const char *set_context_in_breakadd_cmd(expand_T *xp, const char *arg, cm if (cmdidx == CMD_breakadd) { breakpt_expand_what = EXP_BREAKPT_ADD; - } else { + } else if (cmdidx == CMD_breakdel) { breakpt_expand_what = EXP_BREAKPT_DEL; + } else { + breakpt_expand_what = EXP_PROFDEL; } const char *p = skipwhite(arg); @@ -1681,8 +1684,7 @@ static const char *set_context_in_breakadd_cmd(expand_T *xp, const char *arg, cm } const char *subcmd_start = p; - if (strncmp("file ", p, 5) == 0 - || strncmp("func ", p, 5) == 0) { + if (strncmp("file ", p, 5) == 0 || strncmp("func ", p, 5) == 0) { // :breakadd file [lnum] <filename> // :breakadd func [lnum] <funcname> p += 4; @@ -2067,6 +2069,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa break; case CMD_breakadd: + case CMD_profdel: case CMD_breakdel: return set_context_in_breakadd_cmd(xp, arg, cmdidx); @@ -2424,12 +2427,19 @@ static char *get_breakadd_arg(expand_T *xp FUNC_ATTR_UNUSED, int idx) char *opts[] = { "expr", "file", "func", "here" }; if (idx >= 0 && idx <= 3) { + // breakadd {expr, file, func, here} if (breakpt_expand_what == EXP_BREAKPT_ADD) { return opts[idx]; - } else { + } else if (breakpt_expand_what == EXP_BREAKPT_DEL) { + // breakdel {func, file, here} if (idx <= 2) { return opts[idx + 1]; } + } else { + // profdel {func, file} + if (idx <= 1) { + return opts[idx + 1]; + } } } return NULL; diff --git a/src/nvim/profile.c b/src/nvim/profile.c index 866834fc71..acbaf09a6e 100644 --- a/src/nvim/profile.c +++ b/src/nvim/profile.c @@ -354,7 +354,6 @@ char *get_profile_name(expand_T *xp, int idx) switch (pexpand_what) { case PEXP_SUBCMD: return pexpand_cmds[idx]; - // case PEXP_FUNC: TODO default: return NULL; } @@ -373,13 +372,17 @@ void set_context_in_profile_cmd(expand_T *xp, const char *arg) return; } - if (end_subcmd - arg == 5 && strncmp(arg, "start", 5) == 0) { + if ((end_subcmd - arg == 5 && strncmp(arg, "start", 5) == 0) + || (end_subcmd - arg == 4 && strncmp(arg, "file", 4) == 0)) { xp->xp_context = EXPAND_FILES; xp->xp_pattern = skipwhite(end_subcmd); return; + } else if (end_subcmd - arg == 4 && strncmp(arg, "func", 4) == 0) { + xp->xp_context = EXPAND_USER_FUNC; + xp->xp_pattern = skipwhite(end_subcmd); + return; } - // TODO(tarruda): expand function names after "func" xp->xp_context = EXPAND_NOTHING; } diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 40a23d5af6..a074263359 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -2805,7 +2805,6 @@ func Test_cmdline_complete_breakdel() call assert_equal("\"breakdel here Xtest", @:) call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx') call assert_equal("\"breakdel here ", @:) - endfunc " this was going over the end of IObuff diff --git a/src/nvim/testdir/test_profile.vim b/src/nvim/testdir/test_profile.vim index 4225b91bc4..9165f7bace 100644 --- a/src/nvim/testdir/test_profile.vim +++ b/src/nvim/testdir/test_profile.vim @@ -403,6 +403,47 @@ func Test_profile_completion() call feedkeys(":profile start test_prof\<C-A>\<C-B>\"\<CR>", 'tx') call assert_match('^"profile start.* test_profile\.vim', @:) + + call feedkeys(":profile file test_prof\<Tab>\<C-B>\"\<CR>", 'tx') + call assert_match('"profile file test_profile\.vim', @:) + call feedkeys(":profile file test_prof\<Tab>\<C-B>\"\<CR>", 'tx') + call assert_match('"profile file test_profile\.vim', @:) + call feedkeys(":profile file test_prof \<Tab>\<C-B>\"\<CR>", 'tx') + call assert_match('"profile file test_prof ', @:) + call feedkeys(":profile file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx') + call assert_match('"profile file X1B2C3', @:) + + func Xprof_test() + endfunc + call feedkeys(":profile func Xprof\<Tab>\<C-B>\"\<CR>", 'tx') + call assert_equal('"profile func Xprof_test', @:) + call feedkeys(":profile func Xprof\<Tab>\<C-B>\"\<CR>", 'tx') + call assert_equal('"profile func Xprof_test', @:) + call feedkeys(":profile func Xprof \<Tab>\<C-B>\"\<CR>", 'tx') + call assert_equal('"profile func Xprof ', @:) + call feedkeys(":profile func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx') + call assert_equal('"profile func X1B2C3', @:) + + call feedkeys(":profdel \<C-A>\<C-B>\"\<CR>", 'tx') + call assert_equal('"profdel file func', @:) + call feedkeys(":profdel fu\<Tab>\<C-B>\"\<CR>", 'tx') + call assert_equal('"profdel func', @:) + call feedkeys(":profdel he\<Tab>\<C-B>\"\<CR>", 'tx') + call assert_equal('"profdel he', @:) + call feedkeys(":profdel here \<Tab>\<C-B>\"\<CR>", 'tx') + call assert_equal('"profdel here ', @:) + call feedkeys(":profdel file test_prof\<Tab>\<C-B>\"\<CR>", 'tx') + call assert_equal('"profdel file test_profile.vim', @:) + call feedkeys(":profdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx') + call assert_equal('"profdel file X1B2C3', @:) + call feedkeys(":profdel func Xprof\<Tab>\<C-B>\"\<CR>", 'tx') + call assert_equal('"profdel func Xprof_test', @:) + call feedkeys(":profdel func Xprof_test \<Tab>\<C-B>\"\<CR>", 'tx') + call assert_equal('"profdel func Xprof_test ', @:) + call feedkeys(":profdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx') + call assert_equal('"profdel func X1B2C3', @:) + + delfunc Xprof_test endfunc func Test_profile_errors() |