fix: use new _utils api
This commit is contained in:
parent
616474b919
commit
6e70be0ef9
8 changed files with 37 additions and 28 deletions
|
|
@ -1,14 +1,14 @@
|
|||
local Job = require "plenary.job"
|
||||
local c = require("gopher.config").commands
|
||||
local u = require "gopher._utils"
|
||||
|
||||
---Run any go commands like `go generate`, `go get`, `go mod`
|
||||
---@param cmd string
|
||||
---@param ... string|string[]
|
||||
return function(cmd, ...)
|
||||
local Job = require "plenary.job"
|
||||
local c = require("gopher.config").config.commands
|
||||
local u = require "gopher._utils"
|
||||
|
||||
local args = { ... }
|
||||
if #args == 0 then
|
||||
u.notify("please provice any arguments", "error")
|
||||
u.deferred_notify("please provice any arguments", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
|
|
@ -29,12 +29,15 @@ return function(cmd, ...)
|
|||
args = cmd_args,
|
||||
on_exit = function(_, retval)
|
||||
if retval ~= 0 then
|
||||
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
|
||||
u.notify(cmd .. " " .. unpack(cmd_args), "debug")
|
||||
u.deferred_notify(
|
||||
"command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval,
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
u.deferred_notify(cmd .. " " .. unpack(cmd_args), vim.log.levels.DEBUG)
|
||||
return
|
||||
end
|
||||
|
||||
u.notify("go " .. cmd .. " was success runned", "info")
|
||||
u.deferred_notify("go " .. cmd .. " was success runned", vim.log.levels.INFO)
|
||||
end,
|
||||
}):start()
|
||||
end
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ function M.get_struct_node_at_pos(row, col, bufnr, do_notify)
|
|||
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
|
||||
if ns == nil then
|
||||
if notify then
|
||||
u.notify("struct not found", "warn")
|
||||
u.deferred_notify("struct not found", vim.log.levels.WARN)
|
||||
end
|
||||
else
|
||||
return ns[#ns]
|
||||
|
|
@ -53,7 +53,7 @@ function M.get_func_method_node_at_pos(row, col, bufnr, do_notify)
|
|||
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
|
||||
if ns == nil then
|
||||
if notify then
|
||||
u.notify("function not found", "warn")
|
||||
u.deferred_notify("function not found", vim.log.levels.WARN)
|
||||
end
|
||||
else
|
||||
return ns[#ns]
|
||||
|
|
@ -74,7 +74,7 @@ function M.get_package_node_at_pos(row, col, bufnr, do_notify)
|
|||
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
|
||||
if ns == nil then
|
||||
if notify then
|
||||
u.notify("package not found", "warn")
|
||||
u.deferred_notify("package not found", vim.log.levels.WARN)
|
||||
return nil
|
||||
end
|
||||
else
|
||||
|
|
@ -94,7 +94,7 @@ function M.get_interface_node_at_pos(row, col, bufnr, do_notify)
|
|||
local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
|
||||
if ns == nil then
|
||||
if notify then
|
||||
u.notify("interface not found", "warn")
|
||||
u.deferred_notify("interface not found", vim.log.levels.WARN)
|
||||
end
|
||||
else
|
||||
return ns[#ns]
|
||||
|
|
|
|||
|
|
@ -123,13 +123,19 @@ function M.nodes_at_cursor(query, default, bufnr, row, col)
|
|||
|
||||
local nodes = M.get_all_nodes(query, ft, default, bufnr, row, col)
|
||||
if nodes == nil then
|
||||
u.notify("Unable to find any nodes. Place your cursor on a go symbol and try again", "debug")
|
||||
u.deferred_notify(
|
||||
"Unable to find any nodes. Place your cursor on a go symbol and try again",
|
||||
vim.log.levels.DEBUG
|
||||
)
|
||||
return nil
|
||||
end
|
||||
|
||||
nodes = M.sort_nodes(M.intersect_nodes(nodes, row, col))
|
||||
if nodes == nil or #nodes == 0 then
|
||||
u.notify("Unable to find any nodes at pos. " .. tostring(row) .. ":" .. tostring(col), "debug")
|
||||
u.deferred_notify(
|
||||
"Unable to find any nodes at pos. " .. tostring(row) .. ":" .. tostring(col),
|
||||
vim.log.levels.DEBUG
|
||||
)
|
||||
return nil
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -11,14 +11,14 @@ local function run(cmd_args)
|
|||
args = cmd_args,
|
||||
on_exit = function(_, retval)
|
||||
if retval ~= 0 then
|
||||
u.notify(
|
||||
u.deferred_notify(
|
||||
"command '" .. c.gotests .. " " .. unpack(cmd_args) .. "' exited with code " .. retval,
|
||||
"error"
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
u.notify("unit test(s) generated", "info")
|
||||
u.deferred_notify("unit test(s) generated", vim.log.levels.INFO)
|
||||
end,
|
||||
}):start()
|
||||
end
|
||||
|
|
@ -36,7 +36,7 @@ end
|
|||
function gotests.func_test(parallel)
|
||||
local ns = ts_utils.get_func_method_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0)))
|
||||
if ns == nil or ns.name == nil then
|
||||
u.notify("cursor on func/method and execute the command again", "info")
|
||||
u.deferred_notify("cursor on func/method and execute the command again", vim.log.levels.INFO)
|
||||
return
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ iferr.iferr = function()
|
|||
local data = vim.fn.systemlist(cmd, vim.fn.bufnr "%")
|
||||
|
||||
if vim.v.shell_error ~= 0 then
|
||||
u.notify("command " .. cmd .. " exited with code " .. vim.v.shell_error, "error")
|
||||
u.deferred_notify("command " .. cmd .. " exited with code " .. vim.v.shell_error, vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ local impl = {}
|
|||
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
|
||||
u.notify("put cursor on a struct or specify a receiver", "info")
|
||||
u.deferred_notify("put cursor on a struct or specify a receiver", vim.log.levels.INFO)
|
||||
return ""
|
||||
end
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ function impl.impl(...)
|
|||
iface = vim.fn.input "impl: generating method stubs for interface: "
|
||||
vim.cmd "redraw!"
|
||||
if iface == "" then
|
||||
u.notify("usage: GoImpl f *File io.Reader", "info")
|
||||
u.deferred_notify("usage: GoImpl f *File io.Reader", vim.log.levels.INFO)
|
||||
return
|
||||
end
|
||||
elseif #args == 1 then -- :GoImpl io.Reader
|
||||
|
|
@ -60,9 +60,9 @@ function impl.impl(...)
|
|||
args = cmd_args,
|
||||
on_exit = function(data, retval)
|
||||
if retval ~= 0 then
|
||||
u.notify(
|
||||
u.deferred_notify(
|
||||
"command '" .. c.impl .. " " .. unpack(cmd_args) .. "' exited with code " .. retval,
|
||||
"error"
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
return
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,11 +20,11 @@ local function install(pkg)
|
|||
args = { "install", url },
|
||||
on_exit = function(_, retval)
|
||||
if retval ~= 0 then
|
||||
u.notify("command 'go install " .. url .. "' exited with code " .. retval, "error")
|
||||
u.deferred_notify("command 'go install " .. url .. "' exited with code " .. retval, vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
u.notify("install " .. url .. " finished", "info ")
|
||||
u.deferred_notify("install " .. url .. " finished", vim.log.levels.INFO)
|
||||
end,
|
||||
}):start()
|
||||
end
|
||||
|
|
|
|||
|
|
@ -46,14 +46,14 @@ local function modify(...)
|
|||
args = cmd_args,
|
||||
on_exit = function(data, retval)
|
||||
if retval ~= 0 then
|
||||
u.notify(
|
||||
u.deferred_notify(
|
||||
"command '"
|
||||
.. c.gomodifytags
|
||||
.. " "
|
||||
.. unpack(cmd_args)
|
||||
.. "' exited with code "
|
||||
.. retval,
|
||||
"error"
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
return
|
||||
end
|
||||
|
|
@ -70,7 +70,7 @@ local function modify(...)
|
|||
or tagged["start"] == nil
|
||||
or tagged["start"] == 0
|
||||
then
|
||||
u.notify("failed to set tags " .. vim.inspect(tagged), "error")
|
||||
u.deferred_notify("failed to set tags " .. vim.inspect(tagged), vim.log.levels.ERROR)
|
||||
end
|
||||
|
||||
for i, v in ipairs(tagged.lines) do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue