refactor: migrate to vim.notify from prints

This commit is contained in:
Smirnov Oleksandr 2022-06-24 15:27:08 +03:00
parent b4fd34ec17
commit 0b415c32e8
8 changed files with 40 additions and 22 deletions

View file

@ -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,
}

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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

View file

@ -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()

View file

@ -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