style: reformat all lua code

This commit is contained in:
Smirnov Oleksandr 2022-07-07 14:09:48 +03:00
parent 4fee3543e0
commit 4b83da6d7f
8 changed files with 84 additions and 102 deletions

View file

@ -11,18 +11,16 @@ return function(...)
local cmd_args = vim.list_extend({ "generate" }, args) local cmd_args = vim.list_extend({ "generate" }, args)
Job Job:new({
:new({ command = c.go,
command = c.go, args = cmd_args,
args = cmd_args, on_exit = function(_, retval)
on_exit = function(_, retval) if retval ~= 0 then
if retval ~= 0 then u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error") return
return end
end
u.notify("go generate was success runned", "info") u.notify("go generate was success runned", "info")
end, end,
}) }):start()
:start()
end end

View file

@ -18,18 +18,16 @@ return function(...)
local cmd_args = vim.list_extend({ "get" }, args) local cmd_args = vim.list_extend({ "get" }, args)
Job Job:new({
:new({ command = c.go,
command = c.go, args = cmd_args,
args = cmd_args, on_exit = function(_, retval)
on_exit = function(_, retval) if retval ~= 0 then
if retval ~= 0 then u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error") return
return end
end
u.notify("go get was success runned", "info") u.notify("go get was success runned", "info")
end, end,
}) }):start()
:start()
end end

View file

@ -12,18 +12,16 @@ return function(...)
local cmd_args = vim.list_extend({ "mod" }, args) local cmd_args = vim.list_extend({ "mod" }, args)
Job Job:new({
:new({ command = c.go,
command = c.go, args = cmd_args,
args = cmd_args, on_exit = function(_, retval)
on_exit = function(_, retval) if retval ~= 0 then
if retval ~= 0 then u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error") return
return end
end
u.notify("go mod was success runned", "info") u.notify("go mod was success runned", "info")
end, end,
}) }):start()
:start()
end end

View file

@ -6,20 +6,18 @@ local M = {}
---@param cmd_args table ---@param cmd_args table
local function run(cmd_args) local function run(cmd_args)
Job Job:new({
:new({ command = c.gotests,
command = c.gotests, args = cmd_args,
args = cmd_args, on_exit = function(_, retval)
on_exit = function(_, retval) if retval ~= 0 then
if retval ~= 0 then u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error") return
return end
end
u.notify("unit test(s) generated", "info") u.notify("unit test(s) generated", "info")
end, end,
}) }):start()
:start()
end end
---@param args table ---@param args table

View file

@ -54,20 +54,18 @@ return function(...)
} }
local res_data local res_data
Job Job:new({
:new({ command = c.impl,
command = c.impl, args = cmd_args,
args = cmd_args, on_exit = function(data, retval)
on_exit = function(data, retval) if retval ~= 0 then
if retval ~= 0 then u.notify("command 'impl " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
u.notify("command 'impl " .. unpack(cmd_args) .. "' exited with code " .. retval, "error") return
return end
end
res_data = data:result() res_data = data:result()
end, end,
}) }):sync()
:sync()
local pos = vim.fn.getcurpos()[2] local pos = vim.fn.getcurpos()[2]
table.insert(res_data, 1, "") table.insert(res_data, 1, "")

View file

@ -10,20 +10,18 @@ local urls = {
local function install(pkg) local function install(pkg)
local url = urls[pkg] .. "@latest" local url = urls[pkg] .. "@latest"
Job Job:new({
:new({ command = "go",
command = "go", args = { "install", url },
args = { "install", url }, on_exit = function(_, retval)
on_exit = function(_, retval) if retval ~= 0 then
if retval ~= 0 then u.notify("command 'go install " .. url .. "' exited with code " .. retval, "error")
u.notify("command 'go install " .. url .. "' exited with code " .. retval, "error") return
return end
end
u.notify("install " .. url .. " finished", "info ") u.notify("install " .. url .. " finished", "info ")
end, end,
}) }):start()
:start()
end end
---Install required go deps ---Install required go deps

View file

@ -41,23 +41,21 @@ local function modify(...)
-- get result of "gomodifytags" works -- get result of "gomodifytags" works
local res_data local res_data
Job Job:new({
:new({ command = c.gomodifytags,
command = c.gomodifytags, args = cmd_args,
args = cmd_args, on_exit = function(data, retval)
on_exit = function(data, retval) if retval ~= 0 then
if retval ~= 0 then u.notify(
u.notify( "command 'gomodifytags " .. unpack(cmd_args) .. "' exited with code " .. retval,
"command 'gomodifytags " .. unpack(cmd_args) .. "' exited with code " .. retval, "error"
"error" )
) return
return end
end
res_data = data:result() res_data = data:result()
end, end,
}) }):sync()
:sync()
-- decode goted value -- decode goted value
local tagged = vim.json.decode(table.concat(res_data)) local tagged = vim.json.decode(table.concat(res_data))

View file

@ -9,10 +9,8 @@ describe("gopher.struct_tags", function()
local add = require("gopher.struct_tags").add local add = require("gopher.struct_tags").add
local name = vim.fn.tempname() .. ".go" local name = vim.fn.tempname() .. ".go"
local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_input.go") local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_input.go")
local output_file = vim.fn.join( local output_file =
vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_output.go"), vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_output.go"), "\n")
"\n"
)
vim.fn.writefile(input_file, name) vim.fn.writefile(input_file, name)
vim.cmd("silent exe 'e " .. name .. "'") vim.cmd("silent exe 'e " .. name .. "'")
@ -33,10 +31,8 @@ describe("gopher.struct_tags", function()
local remove = require("gopher.struct_tags").remove local remove = require("gopher.struct_tags").remove
local name = vim.fn.tempname() .. ".go" local name = vim.fn.tempname() .. ".go"
local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_input.go") local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_input.go")
local output_file = vim.fn.join( local output_file =
vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_output.go"), vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_output.go"), "\n")
"\n"
)
vim.fn.writefile(input_file, name) vim.fn.writefile(input_file, name)
vim.cmd("silent exe 'e " .. name .. "'") vim.cmd("silent exe 'e " .. name .. "'")