refactor: remove Trans.define and see offline as first backend

This commit is contained in:
JuanZoran 2023-03-15 22:24:41 +08:00
parent 3981167d38
commit df52f2339c
3 changed files with 8 additions and 44 deletions

View File

@ -1,19 +0,0 @@
---@class Trans
---@field define TransDefine
---@class TransDefine
return {
---@type TransMode[]
modes = {
'normal',
'visual',
'input',
},
-- backends = {
-- 'offline',
-- 'baidu',
-- },
frontends = {
'hover',
}
}

View File

@ -1,8 +1,7 @@
local Trans = require('Trans')
local function set_strategy_opts(conf)
local define = Trans.define
local all_modes = define.modes
local all_modes = Trans.modes
local all_backends = Trans.backend.all_name
local function parse_backend(backend)
@ -35,28 +34,6 @@ local function set_strategy_opts(conf)
end
local function set_frontend_opts(conf)
local all_frontends = Trans.define.frontends
local global_frontend_opts = conf.frontend
local meta = {
__index = function(tbl, key)
tbl[key] = global_frontend_opts[key]
return tbl[key]
end
}
for _, frontend in ipairs(all_frontends) do
local frontend_opts = global_frontend_opts[frontend]
if not frontend_opts then
global_frontend_opts[frontend] = setmetatable({}, meta)
else
setmetatable(frontend_opts, meta)
end
end
end
local function define_highlights(conf)
local set_hl = vim.api.nvim_set_hl
@ -81,6 +58,5 @@ return function(opts)
conf.dir = vim.fn.expand(conf.dir)
set_strategy_opts(conf)
set_frontend_opts(conf)
define_highlights(conf)
end

View File

@ -23,9 +23,16 @@ end
---@class Trans
---@field style table @Style module
---@field cache table<string, TransData> @Cache for translated data object
---@field modes string[] @all modes name
local M = metatable('core', {
style = metatable("style"),
cache = {},
modes = {
'normal',
'visual',
'input',
},
augroup = vim.api.nvim_create_augroup('Trans', { clear = true })
})