all repos

gopher.nvim @ 4b83da6

Minimalistic plugin for Go development
8 files changed, 84 insertions(+), 102 deletions(-)
style: reformat all lua code
Author: Smirnov Oleksandr ss2316544@gmail.com
Committed at: 2022-07-07 14:09:48 +0300
Parent: 4fee354
M lua/gopher/gogenerate.lua

@@ -11,18 +11,16 @@ end

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
M lua/gopher/goget.lua

@@ -18,18 +18,16 @@ end

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
M lua/gopher/gomod.lua

@@ -12,18 +12,16 @@ end

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
M lua/gopher/gotests.lua

@@ -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
M lua/gopher/impl.lua

@@ -54,20 +54,18 @@ iface

} 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, "")
M lua/gopher/installer.lua

@@ -10,20 +10,18 @@ ---@param pkg string

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
M lua/gopher/struct_tags.lua

@@ -41,23 +41,21 @@ end

-- 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 + 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() + res_data = data:result() + end, + }):sync() -- decode goted value local tagged = vim.json.decode(table.concat(res_data))
M spec/gopher_struct_tags_spec.lua

@@ -9,10 +9,8 @@ it("can add json tag to struct", 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 .. "'")

@@ -33,10 +31,8 @@ it("can remove json tag from struct", 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 .. "'")