diff options
| author | zeertzjq <zeertzjq@outlook.com> | 2023-10-02 10:45:33 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-02 10:45:33 +0800 |
| commit | 09a17f91d0d362c6e58bfdbe3ccdeacffb0b44b9 (patch) | |
| tree | 204374657c5c6a7815d4aa612563c32feec18b28 /src/nvim | |
| parent | 9ce1623837a817c3f4f5deff9c8ba862578b6009 (diff) | |
| download | rneovim-09a17f91d0d362c6e58bfdbe3ccdeacffb0b44b9.tar.gz rneovim-09a17f91d0d362c6e58bfdbe3ccdeacffb0b44b9.tar.bz2 rneovim-09a17f91d0d362c6e58bfdbe3ccdeacffb0b44b9.zip | |
refactor: move cmdline completion types to cmdexpand_defs.h (#25465)
Diffstat (limited to 'src/nvim')
60 files changed, 245 insertions, 189 deletions
diff --git a/src/nvim/api/command.c b/src/nvim/api/command.c index eb32f46143..f4c6f646eb 100644 --- a/src/nvim/api/command.c +++ b/src/nvim/api/command.c @@ -17,6 +17,7 @@ #include "nvim/ascii.h" #include "nvim/autocmd.h" #include "nvim/buffer_defs.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/decoration.h" #include "nvim/ex_cmds.h" #include "nvim/ex_docmd.h" diff --git a/src/nvim/arglist.c b/src/nvim/arglist.c index a4221a1562..fb8849541d 100644 --- a/src/nvim/arglist.c +++ b/src/nvim/arglist.c @@ -14,6 +14,7 @@ #include "nvim/autocmd.h" #include "nvim/buffer.h" #include "nvim/charset.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/eval/typval.h" #include "nvim/eval/typval_defs.h" #include "nvim/eval/window.h" diff --git a/src/nvim/arglist.h b/src/nvim/arglist.h index 52894b73a0..bd5cfb4a11 100644 --- a/src/nvim/arglist.h +++ b/src/nvim/arglist.h @@ -2,6 +2,7 @@ #define NVIM_ARGLIST_H #include "nvim/arglist_defs.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/eval/typval_defs.h" #include "nvim/ex_cmds_defs.h" #include "nvim/types.h" diff --git a/src/nvim/autocmd.h b/src/nvim/autocmd.h index b3de57311e..324a31be47 100644 --- a/src/nvim/autocmd.h +++ b/src/nvim/autocmd.h @@ -6,6 +6,7 @@ #include "nvim/api/private/defs.h" #include "nvim/buffer_defs.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/eval/typval_defs.h" #include "nvim/ex_cmds_defs.h" #include "nvim/macros.h" diff --git a/src/nvim/cmdexpand.h b/src/nvim/cmdexpand.h index f37c693a22..81e323c97b 100644 --- a/src/nvim/cmdexpand.h +++ b/src/nvim/cmdexpand.h @@ -1,6 +1,7 @@ #ifndef NVIM_CMDEXPAND_H #define NVIM_CMDEXPAND_H +#include "nvim/cmdexpand_defs.h" #include "nvim/eval/typval_defs.h" #include "nvim/ex_getln.h" #include "nvim/garray.h" @@ -41,9 +42,6 @@ enum { BUF_DIFF_FILTER = 0x2000, }; -/// Type used by ExpandGeneric() -typedef char *(*CompleteListItemGetter)(expand_T *, int); - #ifdef INCLUDE_GENERATED_DECLARATIONS # include "cmdexpand.h.generated.h" #endif diff --git a/src/nvim/cmdexpand_defs.h b/src/nvim/cmdexpand_defs.h new file mode 100644 index 0000000000..a302a32852 --- /dev/null +++ b/src/nvim/cmdexpand_defs.h @@ -0,0 +1,113 @@ +#ifndef NVIM_CMDEXPAND_DEFS_H +#define NVIM_CMDEXPAND_DEFS_H + +#include <stdbool.h> +#include <stddef.h> + +#include "nvim/eval/typval_defs.h" +#include "nvim/types.h" + +typedef enum { + XP_PREFIX_NONE, ///< prefix not used + XP_PREFIX_NO, ///< "no" prefix for bool option + XP_PREFIX_INV, ///< "inv" prefix for bool option +} xp_prefix_T; + +enum { EXPAND_BUF_LEN = 256, }; + +/// used for completion on the command line +typedef struct expand { + char *xp_pattern; ///< start of item to expand + int xp_context; ///< type of expansion + size_t xp_pattern_len; ///< bytes in xp_pattern before cursor + xp_prefix_T xp_prefix; + char *xp_arg; ///< completion function + LuaRef xp_luaref; ///< Ref to Lua completion function + sctx_T xp_script_ctx; ///< SCTX for completion function + int xp_backslash; ///< one of the XP_BS_ values +#ifndef BACKSLASH_IN_FILENAME + bool xp_shell; ///< true for a shell command, more + ///< characters need to be escaped +#endif + int xp_numfiles; ///< number of files found by file name completion + int xp_col; ///< cursor position in line + int xp_selected; ///< selected index in completion + char *xp_orig; ///< originally expanded string + char **xp_files; ///< list of files + char *xp_line; ///< text being completed + char xp_buf[EXPAND_BUF_LEN]; ///< buffer for returned match +} expand_T; + +/// values for xp_backslash +enum { + XP_BS_NONE = 0, ///< nothing special for backslashes + XP_BS_ONE = 1, ///< uses one backslash before a space + XP_BS_THREE = 2, ///< uses three backslashes before a space +}; + +/// values for xp_context when doing command line completion +enum { + EXPAND_UNSUCCESSFUL = -2, + EXPAND_OK = -1, + EXPAND_NOTHING = 0, + EXPAND_COMMANDS, + EXPAND_FILES, + EXPAND_DIRECTORIES, + EXPAND_SETTINGS, + EXPAND_BOOL_SETTINGS, + EXPAND_TAGS, + EXPAND_OLD_SETTING, + EXPAND_HELP, + EXPAND_BUFFERS, + EXPAND_EVENTS, + EXPAND_MENUS, + EXPAND_SYNTAX, + EXPAND_HIGHLIGHT, + EXPAND_AUGROUP, + EXPAND_USER_VARS, + EXPAND_MAPPINGS, + EXPAND_TAGS_LISTFILES, + EXPAND_FUNCTIONS, + EXPAND_USER_FUNC, + EXPAND_EXPRESSION, + EXPAND_MENUNAMES, + EXPAND_USER_COMMANDS, + EXPAND_USER_CMD_FLAGS, + EXPAND_USER_NARGS, + EXPAND_USER_COMPLETE, + EXPAND_ENV_VARS, + EXPAND_LANGUAGE, + EXPAND_COLORS, + EXPAND_COMPILER, + EXPAND_USER_DEFINED, + EXPAND_USER_LIST, + EXPAND_USER_LUA, + EXPAND_SHELLCMD, + EXPAND_SIGN, + EXPAND_PROFILE, + EXPAND_FILETYPE, + EXPAND_FILES_IN_PATH, + EXPAND_OWNSYNTAX, + EXPAND_LOCALES, + EXPAND_HISTORY, + EXPAND_USER, + EXPAND_SYNTIME, + EXPAND_USER_ADDR_TYPE, + EXPAND_PACKADD, + EXPAND_MESSAGES, + EXPAND_MAPCLEAR, + EXPAND_ARGLIST, + EXPAND_DIFF_BUFFERS, + EXPAND_BREAKPOINT, + EXPAND_SCRIPTNAMES, + EXPAND_RUNTIME, + EXPAND_STRING_SETTING, + EXPAND_SETTING_SUBTRACT, + EXPAND_CHECKHEALTH, + EXPAND_LUA, +}; + +/// Type used by ExpandGeneric() +typedef char *(*CompleteListItemGetter)(expand_T *, int); + +#endif // NVIM_CMDEXPAND_DEFS_H diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c index 50bdfd892f..b0490670fe 100644 --- a/src/nvim/cmdhist.c +++ b/src/nvim/cmdhist.c @@ -12,6 +12,7 @@ #include "nvim/ascii.h" #include "nvim/charset.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/cmdhist.h" #include "nvim/eval/typval.h" #include "nvim/ex_cmds.h" diff --git a/src/nvim/cmdhist.h b/src/nvim/cmdhist.h index a0f2ab6934..2b7e47e38e 100644 --- a/src/nvim/cmdhist.h +++ b/src/nvim/cmdhist.h @@ -1,6 +1,7 @@ #ifndef NVIM_CMDHIST_H #define NVIM_CMDHIST_H +#include "nvim/cmdexpand_defs.h" #include "nvim/eval/typval_defs.h" #include "nvim/ex_cmds_defs.h" #include "nvim/os/time.h" diff --git a/src/nvim/debugger.c b/src/nvim/debugger.c index 3d5f27e76c..755579a3bc 100644 --- a/src/nvim/debugger.c +++ b/src/nvim/debugger.c @@ -12,6 +12,7 @@ #include "nvim/ascii.h" #include "nvim/charset.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/debugger.h" #include "nvim/drawscreen.h" #include "nvim/eval.h" diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 0bf26b2451..014335f5ed 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -21,6 +21,7 @@ #include "nvim/buffer_defs.h" #include "nvim/channel.h" #include "nvim/charset.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/cmdhist.h" #include "nvim/cursor.h" #include "nvim/edit.h" diff --git a/src/nvim/eval.h b/src/nvim/eval.h index be69cd5657..38bcf8f50d 100644 --- a/src/nvim/eval.h +++ b/src/nvim/eval.h @@ -6,6 +6,7 @@ #include "nvim/buffer_defs.h" #include "nvim/channel.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/eval/typval_defs.h" #include "nvim/event/time.h" #include "nvim/ex_cmds_defs.h" diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 5bfce7c272..ee70731c7c 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -33,6 +33,7 @@ #include "nvim/channel.h" #include "nvim/charset.h" #include "nvim/cmdexpand.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/context.h" #include "nvim/cursor.h" #include "nvim/diff.h" diff --git a/src/nvim/eval/funcs.h b/src/nvim/eval/funcs.h index 5dab12787b..5f6132f68c 100644 --- a/src/nvim/eval/funcs.h +++ b/src/nvim/eval/funcs.h @@ -6,6 +6,7 @@ #include "nvim/api/private/dispatch.h" #include "nvim/buffer_defs.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/eval/typval_defs.h" #include "nvim/types.h" diff --git a/src/nvim/eval/typval_defs.h b/src/nvim/eval/typval_defs.h index d5e8cb0109..c0b5416a05 100644 --- a/src/nvim/eval/typval_defs.h +++ b/src/nvim/eval/typval_defs.h @@ -115,6 +115,19 @@ typedef enum { VAR_BLOB, ///< Blob, .v_blob is used. } VarType; +/// Type values for type(). +enum { + VAR_TYPE_NUMBER = 0, + VAR_TYPE_STRING = 1, + VAR_TYPE_FUNC = 2, + VAR_TYPE_LIST = 3, + VAR_TYPE_DICT = 4, + VAR_TYPE_FLOAT = 5, + VAR_TYPE_BOOL = 6, + VAR_TYPE_SPECIAL = 7, + VAR_TYPE_BLOB = 10, +}; + /// Structure that holds an internal variable value typedef struct { VarType v_type; ///< Variable type. diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 8d85c55e15..6b9801b805 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -14,6 +14,7 @@ #include "nvim/ascii.h" #include "nvim/autocmd.h" #include "nvim/charset.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/debugger.h" #include "nvim/eval.h" #include "nvim/eval/encode.h" diff --git a/src/nvim/eval/userfunc.h b/src/nvim/eval/userfunc.h index 562c549b4b..c3fe56d30c 100644 --- a/src/nvim/eval/userfunc.h +++ b/src/nvim/eval/userfunc.h @@ -4,6 +4,7 @@ #include <stdbool.h> #include <stddef.h> +#include "nvim/cmdexpand_defs.h" #include "nvim/eval.h" #include "nvim/eval/typval_defs.h" #include "nvim/ex_cmds_defs.h" diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 127397d9fa..eb1ce5457e 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -27,6 +27,7 @@ #include "nvim/change.h" #include "nvim/channel.h" #include "nvim/charset.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/cmdhist.h" #include "nvim/cursor.h" #include "nvim/decoration.h" diff --git a/src/nvim/ex_cmds_defs.h b/src/nvim/ex_cmds_defs.h index 78f880db56..111e9539c4 100644 --- a/src/nvim/ex_cmds_defs.h +++ b/src/nvim/ex_cmds_defs.h @@ -5,6 +5,7 @@ #include <stdint.h> #include "nvim/eval/typval_defs.h" +#include "nvim/ex_eval_defs.h" #include "nvim/normal.h" #include "nvim/pos.h" #include "nvim/regexp_defs.h" @@ -69,20 +70,20 @@ #define EX_FILE1 (EX_FILES | EX_NOSPC) // 1 file, defaults to current file #define EX_WORD1 (EX_EXTRA | EX_NOSPC) // one extra word allowed -// values for cmd_addr_type +/// values for cmd_addr_type typedef enum { - ADDR_LINES, // buffer line numbers - ADDR_WINDOWS, // window number - ADDR_ARGUMENTS, // argument number - ADDR_LOADED_BUFFERS, // buffer number of loaded buffer - ADDR_BUFFERS, // buffer number - ADDR_TABS, // tab page number - ADDR_TABS_RELATIVE, // Tab page that only relative - ADDR_QUICKFIX_VALID, // quickfix list valid entry number - ADDR_QUICKFIX, // quickfix list entry number - ADDR_UNSIGNED, // positive count or zero, defaults to 1 - ADDR_OTHER, // something else, use line number for '$', '%', etc. - ADDR_NONE, // no range used + ADDR_LINES, ///< buffer line numbers + ADDR_WINDOWS, ///< window number + ADDR_ARGUMENTS, ///< argument number + ADDR_LOADED_BUFFERS, ///< buffer number of loaded buffer + ADDR_BUFFERS, ///< buffer number + ADDR_TABS, ///< tab page number + ADDR_TABS_RELATIVE, ///< Tab page that only relative + ADDR_QUICKFIX_VALID, ///< quickfix list valid entry number + ADDR_QUICKFIX, ///< quickfix list entry number + ADDR_UNSIGNED, ///< positive count or zero, defaults to 1 + ADDR_OTHER, ///< something else, use line number for '$', '%', etc. + ADDR_NONE, ///< no range used } cmd_addr_T; typedef struct exarg exarg_T; @@ -128,54 +129,13 @@ typedef char *(*LineGetter)(int, void *, int, bool); /// Structure for command definition. typedef struct cmdname { - char *cmd_name; ///< Name of the command. - ex_func_T cmd_func; ///< Function with implementation of this command. - ex_preview_func_T cmd_preview_func; ///< Preview callback function of this command. - uint32_t cmd_argt; ///< Relevant flags from the declared above. - cmd_addr_T cmd_addr_type; ///< Flag for address type. + char *cmd_name; ///< Name of the command. + ex_func_T cmd_func; ///< Function with implementation of this command. + ex_preview_func_T cmd_preview_func; ///< Preview callback function of this command. + uint32_t cmd_argt; ///< Relevant flags from the declared above. + cmd_addr_T cmd_addr_type; ///< Flag for address type. } CommandDefinition; -// A list used for saving values of "emsg_silent". Used by ex_try() to save the -// value of "emsg_silent" if it was non-zero. When this is done, the CSF_SILENT -// flag below is set. -typedef struct eslist_elem eslist_T; -struct eslist_elem { - int saved_emsg_silent; // saved value of "emsg_silent" - eslist_T *next; // next element on the list -}; - -// For conditional commands a stack is kept of nested conditionals. -// When cs_idx < 0, there is no conditional command. -enum { - CSTACK_LEN = 50, -}; - -typedef struct { - int cs_flags[CSTACK_LEN]; // CSF_ flags - char cs_pending[CSTACK_LEN]; // CSTP_: what's pending in ":finally" - union { - void *csp_rv[CSTACK_LEN]; // return typeval for pending return - void *csp_ex[CSTACK_LEN]; // exception for pending throw - } cs_pend; - void *cs_forinfo[CSTACK_LEN]; // info used by ":for" - int cs_line[CSTACK_LEN]; // line nr of ":while"/":for" line - int cs_idx; // current entry, or -1 if none - int cs_looplevel; // nr of nested ":while"s and ":for"s - int cs_trylevel; // nr of nested ":try"s - eslist_T *cs_emsg_silent_list; // saved values of "emsg_silent" - int cs_lflags; // loop flags: CSL_ flags -} cstack_T; -#define cs_rettv cs_pend.csp_rv -#define cs_exception cs_pend.csp_ex - -// Flags for the cs_lflags item in cstack_T. -enum { - CSL_HAD_LOOP = 1, // just found ":while" or ":for" - CSL_HAD_ENDLOOP = 2, // just found ":endwhile" or ":endfor" - CSL_HAD_CONT = 4, // just found ":continue" - CSL_HAD_FINA = 8, // just found ":finally" -}; - /// Arguments used for Ex commands. struct exarg { char *arg; ///< argument of the command @@ -222,41 +182,6 @@ struct exarg { #define EXFLAG_NR 0x02 // '#': number #define EXFLAG_PRINT 0x04 // 'p': print -typedef enum { - XP_PREFIX_NONE, ///< prefix not used - XP_PREFIX_NO, ///< "no" prefix for bool option - XP_PREFIX_INV, ///< "inv" prefix for bool option -} xp_prefix_T; - -// used for completion on the command line -struct expand { - char *xp_pattern; // start of item to expand - int xp_context; // type of expansion - size_t xp_pattern_len; // bytes in xp_pattern before cursor - xp_prefix_T xp_prefix; - char *xp_arg; // completion function - LuaRef xp_luaref; // Ref to Lua completion function - sctx_T xp_script_ctx; // SCTX for completion function - int xp_backslash; // one of the XP_BS_ values -#ifndef BACKSLASH_IN_FILENAME - int xp_shell; // true for a shell command, more - // characters need to be escaped -#endif - int xp_numfiles; // number of files found by file name completion - int xp_col; // cursor position in line - int xp_selected; // selected index in completion - char *xp_orig; // originally expanded string - char **xp_files; // list of files - char *xp_line; // text being completed -#define EXPAND_BUF_LEN 256 - char xp_buf[EXPAND_BUF_LEN]; // buffer for returned match -}; - -// values for xp_backslash -#define XP_BS_NONE 0 // nothing special for backslashes -#define XP_BS_ONE 1 // uses one backslash before a space -#define XP_BS_THREE 2 // uses three backslashes before a space - enum { CMOD_SANDBOX = 0x0001, ///< ":sandbox" CMOD_SILENT = 0x0002, ///< ":silent" diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 02783e032b..ff036dbd42 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -22,6 +22,7 @@ #include "nvim/change.h" #include "nvim/charset.h" #include "nvim/cmdexpand.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/cursor.h" #include "nvim/debugger.h" #include "nvim/digraph.h" diff --git a/src/nvim/ex_docmd.h b/src/nvim/ex_docmd.h index 0fd14c81d3..59f45fce88 100644 --- a/src/nvim/ex_docmd.h +++ b/src/nvim/ex_docmd.h @@ -4,6 +4,7 @@ #include <stdbool.h> #include "nvim/buffer_defs.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/ex_cmds_defs.h" #include "nvim/getchar_defs.h" #include "nvim/globals.h" diff --git a/src/nvim/ex_eval_defs.h b/src/nvim/ex_eval_defs.h index 3ad3368900..6713cdb549 100644 --- a/src/nvim/ex_eval_defs.h +++ b/src/nvim/ex_eval_defs.h @@ -5,6 +5,37 @@ #include "nvim/pos.h" +/// A list used for saving values of "emsg_silent". Used by ex_try() to save the +/// value of "emsg_silent" if it was non-zero. When this is done, the CSF_SILENT +/// flag below is set. +typedef struct eslist_elem eslist_T; +struct eslist_elem { + int saved_emsg_silent; ///< saved value of "emsg_silent" + eslist_T *next; ///< next element on the list +}; + +/// For conditional commands a stack is kept of nested conditionals. +/// When cs_idx < 0, there is no conditional command. +enum { CSTACK_LEN = 50, }; + +typedef struct { + int cs_flags[CSTACK_LEN]; ///< CSF_ flags + char cs_pending[CSTACK_LEN]; ///< CSTP_: what's pending in ":finally" + union { + void *csp_rv[CSTACK_LEN]; ///< return typeval for pending return + void *csp_ex[CSTACK_LEN]; ///< exception for pending throw + } cs_pend; + void *cs_forinfo[CSTACK_LEN]; ///< info used by ":for" + int cs_line[CSTACK_LEN]; ///< line nr of ":while"/":for" line + int cs_idx; ///< current entry, or -1 if none + int cs_looplevel; ///< nr of nested ":while"s and ":for"s + int cs_trylevel; ///< nr of nested ":try"s + eslist_T *cs_emsg_silent_list; ///< saved values of "emsg_silent" + int cs_lflags; ///< loop flags: CSL_ flags +} cstack_T; +#define cs_rettv cs_pend.csp_rv +#define cs_exception cs_pend.csp_ex + /// There is no CSF_IF, the lack of CSF_WHILE, CSF_FOR and CSF_TRY means ":if" /// was used. enum { @@ -37,6 +68,14 @@ enum { CSTP_FINISH = 32, ///< ":finish" is pending }; +/// Flags for the cs_lflags item in cstack_T. +enum { + CSL_HAD_LOOP = 1, ///< just found ":while" or ":for" + CSL_HAD_ENDLOOP = 2, ///< just found ":endwhile" or ":endfor" + CSL_HAD_CONT = 4, ///< just found ":continue" + CSL_HAD_FINA = 8, ///< just |