Skip to content

Commit

Permalink
style: reformat all lua code
Browse files Browse the repository at this point in the history
  • Loading branch information
olexsmir committed Jul 7, 2022
1 parent 4fee354 commit 4b83da6
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 103 deletions.
24 changes: 11 additions & 13 deletions lua/gopher/gogenerate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ return function(...)

local cmd_args = vim.list_extend({ "generate" }, args)

Job
:new({
command = c.go,
args = cmd_args,
on_exit = function(_, retval)
if retval ~= 0 then
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
return
end
Job:new({
command = c.go,
args = cmd_args,
on_exit = function(_, retval)
if retval ~= 0 then
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
return
end

u.notify("go generate was success runned", "info")
end,
})
:start()
u.notify("go generate was success runned", "info")
end,
}):start()
end
24 changes: 11 additions & 13 deletions lua/gopher/goget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@ return function(...)

local cmd_args = vim.list_extend({ "get" }, args)

Job
:new({
command = c.go,
args = cmd_args,
on_exit = function(_, retval)
if retval ~= 0 then
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
return
end
Job:new({
command = c.go,
args = cmd_args,
on_exit = function(_, retval)
if retval ~= 0 then
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
return
end

u.notify("go get was success runned", "info")
end,
})
:start()
u.notify("go get was success runned", "info")
end,
}):start()
end
24 changes: 11 additions & 13 deletions lua/gopher/gomod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@ return function(...)

local cmd_args = vim.list_extend({ "mod" }, args)

Job
:new({
command = c.go,
args = cmd_args,
on_exit = function(_, retval)
if retval ~= 0 then
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
return
end
Job:new({
command = c.go,
args = cmd_args,
on_exit = function(_, retval)
if retval ~= 0 then
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
return
end

u.notify("go mod was success runned", "info")
end,
})
:start()
u.notify("go mod was success runned", "info")
end,
}):start()
end
24 changes: 11 additions & 13 deletions lua/gopher/gotests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ local M = {}

---@param cmd_args table
local function run(cmd_args)
Job
:new({
command = c.gotests,
args = cmd_args,
on_exit = function(_, retval)
if retval ~= 0 then
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
return
end
Job:new({
command = c.gotests,
args = cmd_args,
on_exit = function(_, retval)
if retval ~= 0 then
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
return
end

u.notify("unit test(s) generated", "info")
end,
})
:start()
u.notify("unit test(s) generated", "info")
end,
}):start()
end

---@param args table
Expand Down
24 changes: 11 additions & 13 deletions lua/gopher/impl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,18 @@ return function(...)
}

local res_data
Job
:new({
command = c.impl,
args = cmd_args,
on_exit = function(data, retval)
if retval ~= 0 then
u.notify("command 'impl " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
return
end
Job:new({
command = c.impl,
args = cmd_args,
on_exit = function(data, retval)
if retval ~= 0 then
u.notify("command 'impl " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
return
end

res_data = data:result()
end,
})
:sync()
res_data = data:result()
end,
}):sync()

local pos = vim.fn.getcurpos()[2]
table.insert(res_data, 1, "")
Expand Down
24 changes: 11 additions & 13 deletions lua/gopher/installer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ local urls = {
local function install(pkg)
local url = urls[pkg] .. "@latest"

Job
:new({
command = "go",
args = { "install", url },
on_exit = function(_, retval)
if retval ~= 0 then
u.notify("command 'go install " .. url .. "' exited with code " .. retval, "error")
return
end
Job:new({
command = "go",
args = { "install", url },
on_exit = function(_, retval)
if retval ~= 0 then
u.notify("command 'go install " .. url .. "' exited with code " .. retval, "error")
return
end

u.notify("install " .. url .. " finished", "info ")
end,
})
:start()
u.notify("install " .. url .. " finished", "info ")
end,
}):start()
end

---Install required go deps
Expand Down
32 changes: 15 additions & 17 deletions lua/gopher/struct_tags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,21 @@ local function modify(...)

-- get result of "gomodifytags" works
local res_data
Job
:new({
command = c.gomodifytags,
args = cmd_args,
on_exit = function(data, retval)
if retval ~= 0 then
u.notify(
"command 'gomodifytags " .. unpack(cmd_args) .. "' exited with code " .. retval,
"error"
)
return
end

res_data = data:result()
end,
})
:sync()
Job:new({
command = c.gomodifytags,
args = cmd_args,
on_exit = function(data, retval)
if retval ~= 0 then
u.notify(
"command 'gomodifytags " .. unpack(cmd_args) .. "' exited with code " .. retval,
"error"
)
return
end

res_data = data:result()
end,
}):sync()

-- decode goted value
local tagged = vim.json.decode(table.concat(res_data))
Expand Down
12 changes: 4 additions & 8 deletions spec/gopher_struct_tags_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ describe("gopher.struct_tags", function()
local add = require("gopher.struct_tags").add
local name = vim.fn.tempname() .. ".go"
local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_input.go")
local output_file = vim.fn.join(
vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_output.go"),
"\n"
)
local output_file =
vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_output.go"), "\n")

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

vim.fn.writefile(input_file, name)
vim.cmd("silent exe 'e " .. name .. "'")
Expand Down

0 comments on commit 4b83da6

Please sign in to comment.