style: code format use lua_ls
This commit is contained in:
@@ -4,22 +4,22 @@ local function trans()
|
||||
|
||||
-- TODO : trim empty lines in the beginning and the end
|
||||
for index, line in ipairs(lines) do
|
||||
if line:match('%S+') then
|
||||
if line:match '%S+' then
|
||||
table.insert(paragraphs, { index - 1, line })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local Trans = require('Trans')
|
||||
local Trans = require 'Trans'
|
||||
local baidu = Trans.backend.baidu
|
||||
---@cast baidu Baidu
|
||||
|
||||
for _, line in ipairs(paragraphs) do
|
||||
local query = baidu.get_query({
|
||||
local query = baidu.get_query {
|
||||
str = line[2],
|
||||
from = "en",
|
||||
to = "zh",
|
||||
})
|
||||
from = 'en',
|
||||
to = 'zh',
|
||||
}
|
||||
|
||||
Trans.curl.get(baidu.uri, {
|
||||
query = query,
|
||||
@@ -27,9 +27,9 @@ local function trans()
|
||||
-- vim.print(output)
|
||||
local body = output.body
|
||||
local status, ret = pcall(vim.json.decode, body)
|
||||
assert(status and ret, "Failed to parse json:" .. vim.inspect(body))
|
||||
assert(status and ret, 'Failed to parse json:' .. vim.inspect(body))
|
||||
local result = ret.trans_result
|
||||
assert(result, "Failed to get result: " .. vim.inspect(ret))
|
||||
assert(result, 'Failed to get result: ' .. vim.inspect(ret))
|
||||
|
||||
|
||||
result = result[1]
|
||||
@@ -38,7 +38,7 @@ local function trans()
|
||||
})
|
||||
end
|
||||
|
||||
local ns = vim.api.nvim_create_namespace("Trans")
|
||||
local ns = vim.api.nvim_create_namespace 'Trans'
|
||||
for _, line in ipairs(paragraphs) do
|
||||
local index = line[1]
|
||||
local co = coroutine.running()
|
||||
@@ -60,12 +60,12 @@ local function trans()
|
||||
Trans.util.main_loop(function()
|
||||
vim.api.nvim_buf_set_extmark(0, ns, index, #line[2], {
|
||||
virt_lines = {
|
||||
{ { translation, "MoreMsg" } }
|
||||
{ { translation, 'MoreMsg' } },
|
||||
},
|
||||
})
|
||||
end)
|
||||
|
||||
print('done')
|
||||
print 'done'
|
||||
end
|
||||
-- TODO :双语翻译
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user