refactor: use actions

This commit is contained in:
Folke Lemaitre 2024-11-11 08:57:18 +01:00
parent 3f404079dc
commit f40a2a1faa
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
7 changed files with 100 additions and 64 deletions

View file

@ -1,8 +1,35 @@
---@class lazyvim.util.cmp
local M = {}
---@return string?
function M.ai_accept() end
---@alias lazyvim.util.cmp.Action fun():boolean?
---@type table<string, lazyvim.util.cmp.Action>
M.actions = {
-- Native Snippets
snippet_forward = function()
if vim.snippet.active({ direction = 1 }) then
vim.schedule(function()
vim.snippet.jump(1)
end)
return true
end
end,
}
---@param actions string[]
---@param fallback? string|fun()
function M.map(actions, fallback)
return function()
for _, name in ipairs(actions) do
if M.actions[name] then
local ret = M.actions[name]()
if ret then
return true
end
end
end
return type(fallback) == "function" and fallback() or fallback
end
end
---@alias Placeholder {n:number, text:string}