diff --git a/lua/gopher/_utils/init.lua b/lua/gopher/_utils/init.lua index aa4537f..bb25bf8 100644 --- a/lua/gopher/_utils/init.lua +++ b/lua/gopher/_utils/init.lua @@ -36,4 +36,12 @@ return { return false end, + + ---@param msg string + ---@param lvl string + notify = function(msg, lvl) + vim.defer_fn(function() + vim.notify(msg, lvl) + end, 0) + end, } diff --git a/lua/gopher/gogenerate.lua b/lua/gopher/gogenerate.lua index 1820e5f..ddf756d 100644 --- a/lua/gopher/gogenerate.lua +++ b/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 @@ return function(...) 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() diff --git a/lua/gopher/goget.lua b/lua/gopher/goget.lua index 2bbb73a..72d1f07 100644 --- a/lua/gopher/goget.lua +++ b/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 @@ return function(...) 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() diff --git a/lua/gopher/gomod.lua b/lua/gopher/gomod.lua index 8bd6703..751b1ae 100644 --- a/lua/gopher/gomod.lua +++ b/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 @@ return function(...) 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() diff --git a/lua/gopher/gotests.lua b/lua/gopher/gotests.lua index 4188e6e..d7cd47c 100644 --- a/lua/gopher/gotests.lua +++ b/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 @@ local function run(cmd_args) 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() diff --git a/lua/gopher/impl.lua b/lua/gopher/impl.lua index 1ea1bef..363dc5f 100644 --- a/lua/gopher/impl.lua +++ b/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 @@ return function(...) 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 @@ return function(...) 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 diff --git a/lua/gopher/installer.lua b/lua/gopher/installer.lua index a1afdef..cfd7a00 100644 --- a/lua/gopher/installer.lua +++ b/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 @@ local function install(pkg) :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() diff --git a/lua/gopher/struct_tags.lua b/lua/gopher/struct_tags.lua index 3e64dc6..f82a641 100644 --- a/lua/gopher/struct_tags.lua +++ b/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 @@ local function modify(...) 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 @@ local function modify(...) 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