Trans.nvim/lua/Trans/strategy/fallback.lua

28 lines
736 B
Lua
Raw Normal View History

2023-05-06 11:38:37 +08:00
---Fallback query strategy
---@param data TransData
---@return boolean @true if query success
return function(data)
local result = data.result
local update
for _, backend in ipairs(data.backends) do
local name = backend.name
if backend.no_wait then
---@cast backend TransOfflineBackend
backend.query(data)
else
---@cast backend TransOnlineBackend
require 'Trans'.backend.do_query(data, backend)
update = update or data.frontend:wait()
while result[name] == nil and update(backend) do
end
end
---@cast backend TransBackend
if result[name] then return true end
end
return false
end