docs: add function explain doc
This commit is contained in:
@@ -3,16 +3,18 @@ local conf = Trans.conf
|
||||
local frontend_opts = conf.frontend
|
||||
|
||||
|
||||
---Setup frontend Keymaps
|
||||
---@param frontend TransFrontend
|
||||
local function set_frontend_keymap(frontend)
|
||||
local set = vim.keymap.set
|
||||
local keymap_opts = { silent = true, expr = true }
|
||||
local keymap_opts = { silent = true, expr = false, }
|
||||
|
||||
for action, key in pairs(frontend.opts.keymap) do
|
||||
for action, key in pairs(frontend.opts.keymaps) do
|
||||
set('n', key, function()
|
||||
local instance = frontend.get_active_instance()
|
||||
|
||||
if instance then
|
||||
instance:execute(action)
|
||||
coroutine.wrap(instance.execute)(instance, action)
|
||||
else
|
||||
return key
|
||||
end
|
||||
@@ -21,11 +23,21 @@ local function set_frontend_keymap(frontend)
|
||||
end
|
||||
|
||||
|
||||
local M = setmetatable({}, {
|
||||
---@class TransFrontend
|
||||
---@field opts TransFrontendOpts
|
||||
---@field get_active_instance fun():TransFrontend?
|
||||
---@field process fun(data: TransData, result: TransResult)
|
||||
---@field wait fun(self: TransFrontend, result: TransResult, name: string, timeout: integer)
|
||||
---@field execute fun(action: string) @Execute action for frontend instance
|
||||
|
||||
---@class Trans
|
||||
---@field frontend TransFrontend
|
||||
return setmetatable({}, {
|
||||
__index = function(self, name)
|
||||
local opts = vim.tbl_extend('keep', frontend_opts[name] or {}, frontend_opts.default)
|
||||
local frontend = require('Trans.frontend.' .. name)
|
||||
|
||||
---@type TransFrontend
|
||||
local frontend = require('Trans.frontend.' .. name)
|
||||
|
||||
frontend.opts = opts
|
||||
self[name] = frontend
|
||||
@@ -35,7 +47,3 @@ local M = setmetatable({}, {
|
||||
return frontend
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user