diff options
| author | zeertzjq <zeertzjq@outlook.com> | 2023-01-15 08:38:23 +0800 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-15 08:38:23 +0800 | 
| commit | 9dd590327334d2e0f0fb6eed06b36f337528489e (patch) | |
| tree | f5e7e5b7e0ec6e4e0a5da3b38f5d759ff06c0c54 /src/nvim/cmdexpand.c | |
| parent | fe17cd50fbff5ebed44b6b0d46f3dc933696c1da (diff) | |
| parent | 064fdad98c6eed5f42b72eeeb3efe458fefb377d (diff) | |
| download | rneovim-9dd590327334d2e0f0fb6eed06b36f337528489e.tar.gz rneovim-9dd590327334d2e0f0fb6eed06b36f337528489e.tar.bz2 rneovim-9dd590327334d2e0f0fb6eed06b36f337528489e.zip | |
Merge pull request #21806 from zeertzjq/vim-8.2.4565
vim-patch:8.2.{4563,4565,4570}: cmdline completion for :breakadd, :breakdel, :profdel
Diffstat (limited to 'src/nvim/cmdexpand.c')
| -rw-r--r-- | src/nvim/cmdexpand.c | 88 | 
1 files changed, 88 insertions, 0 deletions
| diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index a1f15fabb6..ca19d6de95 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -1658,6 +1658,62 @@ static const char *set_context_in_lang_cmd(expand_T *xp, const char *arg)    return NULL;  } +static enum { +  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. +static const char *set_context_in_breakadd_cmd(expand_T *xp, const char *arg, cmdidx_T cmdidx) +{ +  xp->xp_context = EXPAND_BREAKPOINT; +  xp->xp_pattern = (char *)arg; + +  if (cmdidx == CMD_breakadd) { +    breakpt_expand_what = EXP_BREAKPT_ADD; +  } else if (cmdidx == CMD_breakdel) { +    breakpt_expand_what = EXP_BREAKPT_DEL; +  } else { +    breakpt_expand_what = EXP_PROFDEL; +  } + +  const char *p = skipwhite(arg); +  if (*p == NUL) { +    return NULL; +  } +  const char *subcmd_start = p; + +  if (strncmp("file ", p, 5) == 0 || strncmp("func ", p, 5) == 0) { +    // :breakadd file [lnum] <filename> +    // :breakadd func [lnum] <funcname> +    p += 4; +    p = skipwhite(p); + +    // skip line number (if specified) +    if (ascii_isdigit(*p)) { +      p = skipdigits(p); +      if (*p != ' ') { +        xp->xp_context = EXPAND_NOTHING; +        return NULL; +      } +      p = skipwhite(p); +    } +    if (strncmp("file", subcmd_start, 4) == 0) { +      xp->xp_context = EXPAND_FILES; +    } else { +      xp->xp_context = EXPAND_USER_FUNC; +    } +    xp->xp_pattern = (char *)p; +  } else if (strncmp("expr ", p, 5) == 0) { +    // :breakadd expr <expression> +    xp->xp_context = EXPAND_EXPRESSION; +    xp->xp_pattern = skipwhite(p + 5); +  } + +  return NULL; +} +  /// Set the completion context in "xp" for command "cmd" with index "cmdidx".  /// The argument to the command is "arg" and the argument flags is "argt".  /// For user-defined commands and for environment variables, "context" has the @@ -2012,6 +2068,11 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa      xp->xp_pattern = (char *)arg;      break; +  case CMD_breakadd: +  case CMD_profdel: +  case CMD_breakdel: +    return set_context_in_breakadd_cmd(xp, arg, cmdidx); +    case CMD_lua:      xp->xp_context = EXPAND_LUA;      break; @@ -2359,6 +2420,32 @@ static char *get_behave_arg(expand_T *xp FUNC_ATTR_UNUSED, int idx)  }  /// Function given to ExpandGeneric() to obtain the possible arguments of the +/// ":breakadd {expr, file, func, here}" command. +/// ":breakdel {func, file, here}" command. +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 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; +} + +/// Function given to ExpandGeneric() to obtain the possible arguments of the  /// ":messages {clear}" command.  static char *get_messages_arg(expand_T *xp FUNC_ATTR_UNUSED, int idx)  { @@ -2442,6 +2529,7 @@ static int ExpandOther(expand_T *xp, regmatch_T *rmp, char ***matches, int *numM      { EXPAND_ENV_VARS, get_env_name, true, true },      { EXPAND_USER, get_users, true, false },      { EXPAND_ARGLIST, get_arglist_name, true, false }, +    { EXPAND_BREAKPOINT, get_breakadd_arg, true, true },      { EXPAND_CHECKHEALTH, get_healthcheck_names, true, false },    };    int ret = FAIL; | 
