feat(mapping): plug and expose API (#346)

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham
2024-08-28 23:56:00 -04:00
committed by GitHub
parent 8a683b053b
commit 2e6a26240e
5 changed files with 201 additions and 57 deletions

27
lua/avante/api.lua Normal file
View File

@@ -0,0 +1,27 @@
local Utils = require("avante.utils")
---@class avante.ApiToggle
---@operator call(): boolean
---@field debug ToggleBind.wrap
---@field hint ToggleBind.wrap
---
---@class avante.Api
---@field ask fun(): boolean
---@field edit fun(): nil
---@field refresh fun(): nil
---@field toggle avante.ApiToggle
return setmetatable({}, {
__index = function(t, k)
local module = require("avante")
---@class AvailableApi: ApiCaller
---@field api? boolean
local has = module[k]
if type(has) ~= "table" or not has.api then
Utils.warn(k .. " is not a valid avante's API method", { once = true })
return
end
t[k] = has
return t[k]
end,
}) --[[@as avante.Api]]