refactor: add cache logic
This commit is contained in:
@@ -1,17 +1,40 @@
|
||||
local Trans = require('Trans')
|
||||
local M = Trans.metatable('frontend')
|
||||
local conf = Trans.conf
|
||||
local frontend_opts = conf.frontend
|
||||
|
||||
|
||||
-- local default_opts = vim.deepcopy(Trans.conf.frontend)
|
||||
-- for name, private_opts in pairs(result or {}) do
|
||||
-- local opts = vim.tbl_extend('keep', Trans.conf.backend[name] or {}, default_opts, private_opts)
|
||||
local function set_frontend_keymap(frontend)
|
||||
local set = vim.keymap.set
|
||||
local keymap_opts = { silent = true, expr = true }
|
||||
|
||||
for action, key in pairs(frontend.opts.keymap) do
|
||||
set('n', key, function()
|
||||
local instance = frontend.get_active_instance()
|
||||
if instance then
|
||||
instance:execute(action)
|
||||
else
|
||||
return key
|
||||
end
|
||||
end, keymap_opts)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local M = setmetatable({}, {
|
||||
__index = function(self, name)
|
||||
local opts = vim.tbl_extend('keep', frontend_opts[name] or {}, frontend_opts.default)
|
||||
local frontend = require('Trans.frontend.' .. name)
|
||||
|
||||
|
||||
frontend.opts = opts
|
||||
self[name] = frontend
|
||||
|
||||
set_frontend_keymap(frontend)
|
||||
|
||||
return frontend
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
-- local backend = M[name]
|
||||
-- for k, v in pairs(opts) do
|
||||
-- if not backend[k] then
|
||||
-- backend[k] = v
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user