aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/cmdexpand.c14
-rw-r--r--src/nvim/cmdexpand_defs.h1
-rw-r--r--src/nvim/extreg.c33
-rw-r--r--src/nvim/extreg.h1
-rw-r--r--src/nvim/lua/executor.c4
5 files changed, 52 insertions, 1 deletions
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c
index 040a18f889..50f795c590 100644
--- a/src/nvim/cmdexpand.c
+++ b/src/nvim/cmdexpand.c
@@ -1508,6 +1508,14 @@ void set_expand_context(expand_T *xp)
return;
}
+ if (ccline->cmdfirstc == '~') {
+ xp->xp_context = EXPAND_EXTREGS;
+ xp->xp_pattern = ccline->cmdbuff;
+ xp->xp_line = ccline->cmdbuff;
+ xp->xp_col = ccline->cmdpos;
+ return;
+ }
+
// Only handle ':', '>', or '=' command-lines, or expression input
if (ccline->cmdfirstc != ':'
&& ccline->cmdfirstc != '>' && ccline->cmdfirstc != '='
@@ -2970,6 +2978,11 @@ static char *get_arg1_from_lua(char *lua, expand_T *xp, int idx)
return NULL;
}
+static char* get_extreg_arg(expand_T *xp, int idx) {
+ char* ret = get_arg1_from_lua("return vim._extregs.get_provider_names(...)", xp, idx);
+ return ret;
+}
+
/// Completion for the |:marks| command. Given to ExpandGeneric().
/// @param[in] xp Expandy thing 🤷
/// @param[in] idx Index of the item.
@@ -3057,6 +3070,7 @@ static int ExpandOther(char *pat, expand_T *xp, regmatch_T *rmp, char ***matches
{ EXPAND_LSP, get_lsp_arg, true, false },
{ EXPAND_PACKDEL, get_packdel_arg, true, false },
{ EXPAND_PACKUPDATE, get_packupdate_arg, true, false },
+ { EXPAND_EXTREGS, get_extreg_arg, true, false },
};
int ret = FAIL;
diff --git a/src/nvim/cmdexpand_defs.h b/src/nvim/cmdexpand_defs.h
index 9fee7fd06f..5afc2f77e2 100644
--- a/src/nvim/cmdexpand_defs.h
+++ b/src/nvim/cmdexpand_defs.h
@@ -134,6 +134,7 @@ enum {
EXPAND_PACKDEL,
EXPAND_PACKUPDATE,
EXPAND_MARKS,
+ EXPAND_EXTREGS,
};
/// Type used by ExpandGeneric()
diff --git a/src/nvim/extreg.c b/src/nvim/extreg.c
index b416ac8111..455a8e24e5 100644
--- a/src/nvim/extreg.c
+++ b/src/nvim/extreg.c
@@ -855,3 +855,36 @@ int nlua_extregs_get_provider(lua_State *lstate)
lua_pushlightuserdata(lstate, (void *)prov);
return 1;
}
+
+/// Lua: vim._extregs.get_provider_names()
+/// Returns a table of all registered extreg provider names
+int nlua_extregs_get_provider_names(lua_State *lstate)
+{
+ hash_lock(&extreg_providers);
+
+ // First, count the registered providers
+ size_t count = 0;
+ HASHTAB_ITER(&extreg_providers, hi, {
+ extreg_provider_t *prov = HASH_ITEM_TO_EXTREG_PROVIDER(hi);
+ if (prov->registered) {
+ count++;
+ }
+ });
+
+ // Create table with pre-allocated size
+ lua_createtable(lstate, (int)count, 0);
+
+ // Now fill the table
+ size_t idx = 1;
+ HASHTAB_ITER(&extreg_providers, hi, {
+ extreg_provider_t *prov = HASH_ITEM_TO_EXTREG_PROVIDER(hi);
+ if (prov->registered && idx <= count) {
+ lua_pushstring(lstate, prov->name);
+ lua_rawseti(lstate, -2, (int)idx++);
+ }
+ });
+
+ hash_unlock(&extreg_providers);
+
+ return 1; // return the table
+}
diff --git a/src/nvim/extreg.h b/src/nvim/extreg.h
index 5dc8fec367..4137d17e8b 100644
--- a/src/nvim/extreg.h
+++ b/src/nvim/extreg.h
@@ -70,3 +70,4 @@ extern int nlua_extregs_unbind(lua_State *lstate);
extern int nlua_extregs_is_alias(lua_State *lstate);
extern int nlua_extregs_get_provider_name_for_alias(lua_State *lstate);
extern int nlua_extregs_get_provider(lua_State *lstate);
+extern int nlua_extregs_get_provider_names(lua_State *lstate);
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index aa159ef94d..204c5d53a8 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -760,7 +760,7 @@ static void nlua_common_vim_init(lua_State *lstate, bool is_thread)
lua_setfield(lstate, -2, "_empty_dict_mt");
// vim._extregs
- lua_createtable(lstate, 0, 8);
+ lua_createtable(lstate, 0, 9);
lua_pushcfunction(lstate, &nlua_extregs_register);
lua_setfield(lstate, -2, "register");
lua_pushcfunction(lstate, &nlua_extregs_unregister);
@@ -775,6 +775,8 @@ static void nlua_common_vim_init(lua_State *lstate, bool is_thread)
lua_setfield(lstate, -2, "get_provider_name_for_alias");
lua_pushcfunction(lstate, &nlua_extregs_get_provider);
lua_setfield(lstate, -2, "get_provider");
+ lua_pushcfunction(lstate, &nlua_extregs_get_provider_names);
+ lua_setfield(lstate, -2, "get_provider_names");
lua_setfield(lstate, -2, "_extregs");
// vim.uv