fix(input): lua function completion
This commit is contained in:
parent
d886a1bb0b
commit
96b09a0e3c
|
@ -164,7 +164,20 @@ M.completefunc = function(findstart, base)
|
|||
local pieces = split(completion, ",")
|
||||
if pieces[1] == "custom" or pieces[1] == "customlist" then
|
||||
local vimfunc = pieces[2]
|
||||
local ret = vim.fn[vimfunc](base, base, vim.fn.strlen(base))
|
||||
local ret
|
||||
if vim.startswith(vimfunc, "v:lua.") then
|
||||
local load_func = string.format("return %s(...)", vimfunc:sub(7))
|
||||
local luafunc, err = loadstring(load_func)
|
||||
if not luafunc then
|
||||
vim.api.nvim_err_writeln(
|
||||
string.format("Could not find completion function %s: %s", vimfunc, err)
|
||||
)
|
||||
return {}
|
||||
end
|
||||
ret = luafunc(base, base, vim.fn.strlen(base))
|
||||
else
|
||||
ret = vim.fn[vimfunc](base, base, vim.fn.strlen(base))
|
||||
end
|
||||
if pieces[1] == "custom" then
|
||||
ret = split(ret, "\n")
|
||||
end
|
||||
|
|
|
@ -18,6 +18,14 @@ local cases = {
|
|||
prompt = "Complete customlist: ",
|
||||
completion = "customlist,CustomCompleteList",
|
||||
},
|
||||
{
|
||||
prompt = "Complete custom lua: ",
|
||||
completion = "custom,v:lua.custom_complete_func",
|
||||
},
|
||||
{
|
||||
prompt = "Complete customlist: ",
|
||||
completion = "customlist,v:lua.custom_complete_list",
|
||||
},
|
||||
}
|
||||
|
||||
vim.cmd([[
|
||||
|
@ -30,6 +38,14 @@ function! CustomCompleteList(arglead, cmdline, cursorpos)
|
|||
endfunction
|
||||
]])
|
||||
|
||||
function _G.custom_complete_func(arglead, cmdline, cursorpos)
|
||||
return "first\nsecond\nthird"
|
||||
end
|
||||
|
||||
function _G.custom_complete_list(arglead, cmdline, cursorpos)
|
||||
return { "first", "second", "third" }
|
||||
end
|
||||
|
||||
local function next()
|
||||
local opts = cases[idx]
|
||||
if opts then
|
||||
|
|
Loading…
Reference in New Issue