all repos

gopher.nvim @ 0b415c3

Minimalistic plugin for Go development
8 files changed, 40 insertions(+), 22 deletions(-)
refactor: migrate to vim.notify from prints
Author: Smirnov Oleksandr ss2316544@gmail.com
Committed at: 2022-06-24 15:27:08 +0300
Parent: b4fd34e
M lua/gopher/_utils/init.lua

@@ -36,4 +36,12 @@ end

return false end, + + ---@param msg string + ---@param lvl string + notify = function(msg, lvl) + vim.defer_fn(function() + vim.notify(msg, lvl) + end, 0) + end, }
M lua/gopher/gogenerate.lua

@@ -1,4 +1,5 @@

local Job = require "plenary.job" +local u = require "gopher._utils" ---run "go generate" return function(...)

@@ -15,11 +16,11 @@ command = "go",

args = cmd_args, on_exit = function(_, retval) if retval ~= 0 then - print("command exited with code " .. retval) + u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error") return - else - print "command runs successfully" end + + u.notify("go generate was success runned", "info") end, }) :start()
M lua/gopher/goget.lua

@@ -1,4 +1,5 @@

local Job = require "plenary.job" +local u = require "gopher._utils" ---run "go get" return function(...)

@@ -17,11 +18,11 @@ command = "go",

args = cmd_args, on_exit = function(_, retval) if retval ~= 0 then - print("command exited with code " .. retval) + u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error") return - else - print "command runs successfully" end + + u.notify("go get was success runned", "info") end, }) :start()
M lua/gopher/gomod.lua

@@ -1,4 +1,5 @@

local Job = require "plenary.job" +local u = require "gopher._utils" ---run "go mod" return function(...)

@@ -11,11 +12,11 @@ command = "go",

args = cmd_args, on_exit = function(_, retval) if retval ~= 0 then - print("command exited with code " .. retval) + u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error") return - else - print "command runs successfully" end + + u.notify("go mod was success runned", "info") end, }) :start()
M lua/gopher/gotests.lua

@@ -1,5 +1,6 @@

local Job = require "plenary.job" local ts_utils = require "gopher._utils.ts" +local u = require "gopher._utils" local M = {} ---@param cmd_args table

@@ -10,11 +11,11 @@ command = "gotests",

args = cmd_args, on_exit = function(_, retval) if retval ~= 0 then - print("command exited with code " .. retval) + u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error") return end - print "unit test(s) generated" + u.notify("unit test(s) generated", "info") end, }) :start()
M lua/gopher/impl.lua

@@ -1,11 +1,12 @@

local Job = require "plenary.job" local ts_utils = require "gopher._utils.ts" +local u = require "gopher._utils" ---@return string local function get_struct() local ns = ts_utils.get_struct_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0))) if ns == nil then - print "put cursor on struct or specify a receiver" + u.notify("put cursor on a struct or specify a receiver", "info") return "" end

@@ -26,7 +27,8 @@ if #args == 0 then

iface = vim.fn.input "impl: generating method stubs for interface: " vim.cmd "redeaw!" if iface == "" then - print "usage: GoImpl f *File io.Reader" + u.notify("usage: GoImpl f *File io.Reader", "info") + return end elseif #args == 1 then -- :GoImpl io.Reader recv = string.lower(recv) .. " *" .. recv

@@ -57,7 +59,7 @@ command = "impl",

args = cmd_args, on_exit = function(data, retval) if retval ~= 0 then - print("command exited with code " .. retval) + u.notify("command 'impl " .. unpack(cmd_args) .. "' exited with code " .. retval, "error") return end
M lua/gopher/installer.lua

@@ -1,4 +1,5 @@

local Job = require "plenary.job" +local u = require "gopher._utils" local urls = { gomodifytags = "github.com/fatih/gomodifytags", impl = "github.com/josharian/impl",

@@ -13,13 +14,13 @@ Job

:new({ command = "go", args = { "install", url }, - on_exit = function(_, ret_val) - if ret_val ~= 0 then - print("command exited with code " .. ret_val) + on_exit = function(_, retval) + if retval ~= 0 then + u.notify("command 'go install " .. url .. "' exited with code " .. retval, "error") return end - print("install " .. url .. " finished") + u.notify("install " .. url .. " finished", "info ") end, }) :start()
M lua/gopher/struct_tags.lua

@@ -1,6 +1,6 @@

local Job = require "plenary.job" local ts_utils = require "gopher._utils.ts" -local utils = require "gopher._utils" +local u = require "gopher._utils" local M = {} local function modify(...)

@@ -46,7 +46,10 @@ command = "gomodifytags",

args = cmd_args, on_exit = function(data, retval) if retval ~= 0 then - print("command exited with code " .. retval) + u.notify( + "command 'gomodifytags " .. unpack(cmd_args) .. "' exited with code " .. retval, + "error" + ) return end

@@ -63,11 +66,11 @@ or tagged.lines == nil

or tagged["start"] == nil or tagged["start"] == 0 then - print("failed to set tags " .. vim.inspect(tagged)) + u.notify("failed to set tags " .. vim.inspect(tagged), "error") end for i, v in ipairs(tagged.lines) do - tagged.lines[i] = utils.rtrim(v) + tagged.lines[i] = u.rtrim(v) end -- write goted tags