refactor: migrate to vim.notify from prints
This commit is contained in:
parent
b4fd34ec17
commit
0b415c32e8
8 changed files with 40 additions and 22 deletions
|
|
@ -36,4 +36,12 @@ return {
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
---@param msg string
|
||||||
|
---@param lvl string
|
||||||
|
notify = function(msg, lvl)
|
||||||
|
vim.defer_fn(function()
|
||||||
|
vim.notify(msg, lvl)
|
||||||
|
end, 0)
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
local Job = require "plenary.job"
|
local Job = require "plenary.job"
|
||||||
|
local u = require "gopher._utils"
|
||||||
|
|
||||||
---run "go generate"
|
---run "go generate"
|
||||||
return function(...)
|
return function(...)
|
||||||
|
|
@ -15,11 +16,11 @@ return function(...)
|
||||||
args = cmd_args,
|
args = cmd_args,
|
||||||
on_exit = function(_, retval)
|
on_exit = function(_, retval)
|
||||||
if retval ~= 0 then
|
if retval ~= 0 then
|
||||||
print("command exited with code " .. retval)
|
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
|
||||||
return
|
return
|
||||||
else
|
|
||||||
print "command runs successfully"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
u.notify("go generate was success runned", "info")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
:start()
|
:start()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
local Job = require "plenary.job"
|
local Job = require "plenary.job"
|
||||||
|
local u = require "gopher._utils"
|
||||||
|
|
||||||
---run "go get"
|
---run "go get"
|
||||||
return function(...)
|
return function(...)
|
||||||
|
|
@ -17,11 +18,11 @@ return function(...)
|
||||||
args = cmd_args,
|
args = cmd_args,
|
||||||
on_exit = function(_, retval)
|
on_exit = function(_, retval)
|
||||||
if retval ~= 0 then
|
if retval ~= 0 then
|
||||||
print("command exited with code " .. retval)
|
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
|
||||||
return
|
return
|
||||||
else
|
|
||||||
print "command runs successfully"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
u.notify("go get was success runned", "info")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
:start()
|
:start()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
local Job = require "plenary.job"
|
local Job = require "plenary.job"
|
||||||
|
local u = require "gopher._utils"
|
||||||
|
|
||||||
---run "go mod"
|
---run "go mod"
|
||||||
return function(...)
|
return function(...)
|
||||||
|
|
@ -11,11 +12,11 @@ return function(...)
|
||||||
args = cmd_args,
|
args = cmd_args,
|
||||||
on_exit = function(_, retval)
|
on_exit = function(_, retval)
|
||||||
if retval ~= 0 then
|
if retval ~= 0 then
|
||||||
print("command exited with code " .. retval)
|
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
|
||||||
return
|
return
|
||||||
else
|
|
||||||
print "command runs successfully"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
u.notify("go mod was success runned", "info")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
:start()
|
:start()
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
local Job = require "plenary.job"
|
local Job = require "plenary.job"
|
||||||
local ts_utils = require "gopher._utils.ts"
|
local ts_utils = require "gopher._utils.ts"
|
||||||
|
local u = require "gopher._utils"
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
---@param cmd_args table
|
---@param cmd_args table
|
||||||
|
|
@ -10,11 +11,11 @@ local function run(cmd_args)
|
||||||
args = cmd_args,
|
args = cmd_args,
|
||||||
on_exit = function(_, retval)
|
on_exit = function(_, retval)
|
||||||
if retval ~= 0 then
|
if retval ~= 0 then
|
||||||
print("command exited with code " .. retval)
|
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
print "unit test(s) generated"
|
u.notify("unit test(s) generated", "info")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
:start()
|
:start()
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
local Job = require "plenary.job"
|
local Job = require "plenary.job"
|
||||||
local ts_utils = require "gopher._utils.ts"
|
local ts_utils = require "gopher._utils.ts"
|
||||||
|
local u = require "gopher._utils"
|
||||||
|
|
||||||
---@return string
|
---@return string
|
||||||
local function get_struct()
|
local function get_struct()
|
||||||
local ns = ts_utils.get_struct_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0)))
|
local ns = ts_utils.get_struct_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0)))
|
||||||
if ns == nil then
|
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 ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -26,7 +27,8 @@ return function(...)
|
||||||
iface = vim.fn.input "impl: generating method stubs for interface: "
|
iface = vim.fn.input "impl: generating method stubs for interface: "
|
||||||
vim.cmd "redeaw!"
|
vim.cmd "redeaw!"
|
||||||
if iface == "" then
|
if iface == "" then
|
||||||
print "usage: GoImpl f *File io.Reader"
|
u.notify("usage: GoImpl f *File io.Reader", "info")
|
||||||
|
return
|
||||||
end
|
end
|
||||||
elseif #args == 1 then -- :GoImpl io.Reader
|
elseif #args == 1 then -- :GoImpl io.Reader
|
||||||
recv = string.lower(recv) .. " *" .. recv
|
recv = string.lower(recv) .. " *" .. recv
|
||||||
|
|
@ -57,7 +59,7 @@ return function(...)
|
||||||
args = cmd_args,
|
args = cmd_args,
|
||||||
on_exit = function(data, retval)
|
on_exit = function(data, retval)
|
||||||
if retval ~= 0 then
|
if retval ~= 0 then
|
||||||
print("command exited with code " .. retval)
|
u.notify("command 'impl " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
local Job = require "plenary.job"
|
local Job = require "plenary.job"
|
||||||
|
local u = require "gopher._utils"
|
||||||
local urls = {
|
local urls = {
|
||||||
gomodifytags = "github.com/fatih/gomodifytags",
|
gomodifytags = "github.com/fatih/gomodifytags",
|
||||||
impl = "github.com/josharian/impl",
|
impl = "github.com/josharian/impl",
|
||||||
|
|
@ -13,13 +14,13 @@ local function install(pkg)
|
||||||
:new({
|
:new({
|
||||||
command = "go",
|
command = "go",
|
||||||
args = { "install", url },
|
args = { "install", url },
|
||||||
on_exit = function(_, ret_val)
|
on_exit = function(_, retval)
|
||||||
if ret_val ~= 0 then
|
if retval ~= 0 then
|
||||||
print("command exited with code " .. ret_val)
|
u.notify("command 'go install " .. url .. "' exited with code " .. retval, "error")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
print("install " .. url .. " finished")
|
u.notify("install " .. url .. " finished", "info ")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
:start()
|
:start()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
local Job = require "plenary.job"
|
local Job = require "plenary.job"
|
||||||
local ts_utils = require "gopher._utils.ts"
|
local ts_utils = require "gopher._utils.ts"
|
||||||
local utils = require "gopher._utils"
|
local u = require "gopher._utils"
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local function modify(...)
|
local function modify(...)
|
||||||
|
|
@ -46,7 +46,10 @@ local function modify(...)
|
||||||
args = cmd_args,
|
args = cmd_args,
|
||||||
on_exit = function(data, retval)
|
on_exit = function(data, retval)
|
||||||
if retval ~= 0 then
|
if retval ~= 0 then
|
||||||
print("command exited with code " .. retval)
|
u.notify(
|
||||||
|
"command 'gomodifytags " .. unpack(cmd_args) .. "' exited with code " .. retval,
|
||||||
|
"error"
|
||||||
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -63,11 +66,11 @@ local function modify(...)
|
||||||
or tagged["start"] == nil
|
or tagged["start"] == nil
|
||||||
or tagged["start"] == 0
|
or tagged["start"] == 0
|
||||||
then
|
then
|
||||||
print("failed to set tags " .. vim.inspect(tagged))
|
u.notify("failed to set tags " .. vim.inspect(tagged), "error")
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, v in ipairs(tagged.lines) do
|
for i, v in ipairs(tagged.lines) do
|
||||||
tagged.lines[i] = utils.rtrim(v)
|
tagged.lines[i] = u.rtrim(v)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- write goted tags
|
-- write goted tags
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue