fix: use new _utils api

This commit is contained in:
Smirnov Oleksandr 2023-07-19 23:20:41 +03:00
parent 616474b919
commit 6e70be0ef9
8 changed files with 37 additions and 28 deletions

View file

@ -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` ---Run any go commands like `go generate`, `go get`, `go mod`
---@param cmd string ---@param cmd string
---@param ... string|string[] ---@param ... string|string[]
return function(cmd, ...) return function(cmd, ...)
local Job = require "plenary.job"
local c = require("gopher.config").config.commands
local u = require "gopher._utils"
local args = { ... } local args = { ... }
if #args == 0 then if #args == 0 then
u.notify("please provice any arguments", "error") u.deferred_notify("please provice any arguments", vim.log.levels.ERROR)
return return
end end
@ -29,12 +29,15 @@ return function(cmd, ...)
args = cmd_args, args = cmd_args,
on_exit = function(_, retval) on_exit = function(_, retval)
if retval ~= 0 then if retval ~= 0 then
u.notify("command 'go " .. unpack(cmd_args) .. "' exited with code " .. retval, "error") u.deferred_notify(
u.notify(cmd .. " " .. unpack(cmd_args), "debug") "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 return
end end
u.notify("go " .. cmd .. " was success runned", "info") u.deferred_notify("go " .. cmd .. " was success runned", vim.log.levels.INFO)
end, end,
}):start() }):start()
end end

View file

@ -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) local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
if ns == nil then if ns == nil then
if notify then if notify then
u.notify("struct not found", "warn") u.deferred_notify("struct not found", vim.log.levels.WARN)
end end
else else
return ns[#ns] 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) local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
if ns == nil then if ns == nil then
if notify then if notify then
u.notify("function not found", "warn") u.deferred_notify("function not found", vim.log.levels.WARN)
end end
else else
return ns[#ns] 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) local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
if ns == nil then if ns == nil then
if notify then if notify then
u.notify("package not found", "warn") u.deferred_notify("package not found", vim.log.levels.WARN)
return nil return nil
end end
else 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) local ns = nodes.nodes_at_cursor(query, get_name_defaults(), bufn, row, col)
if ns == nil then if ns == nil then
if notify then if notify then
u.notify("interface not found", "warn") u.deferred_notify("interface not found", vim.log.levels.WARN)
end end
else else
return ns[#ns] return ns[#ns]

View file

@ -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) local nodes = M.get_all_nodes(query, ft, default, bufnr, row, col)
if nodes == nil then 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 return nil
end end
nodes = M.sort_nodes(M.intersect_nodes(nodes, row, col)) nodes = M.sort_nodes(M.intersect_nodes(nodes, row, col))
if nodes == nil or #nodes == 0 then 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 return nil
end end

View file

@ -11,14 +11,14 @@ 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
u.notify( u.deferred_notify(
"command '" .. c.gotests .. " " .. unpack(cmd_args) .. "' exited with code " .. retval, "command '" .. c.gotests .. " " .. unpack(cmd_args) .. "' exited with code " .. retval,
"error" vim.log.levels.ERROR
) )
return return
end end
u.notify("unit test(s) generated", "info") u.deferred_notify("unit test(s) generated", vim.log.levels.INFO)
end, end,
}):start() }):start()
end end
@ -36,7 +36,7 @@ end
function gotests.func_test(parallel) function gotests.func_test(parallel)
local ns = ts_utils.get_func_method_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0))) 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 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 return
end end

View file

@ -9,7 +9,7 @@ iferr.iferr = function()
local data = vim.fn.systemlist(cmd, vim.fn.bufnr "%") local data = vim.fn.systemlist(cmd, vim.fn.bufnr "%")
if vim.v.shell_error ~= 0 then 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 return
end end

View file

@ -8,7 +8,7 @@ local impl = {}
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
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 "" return ""
end end
@ -29,7 +29,7 @@ function impl.impl(...)
iface = vim.fn.input "impl: generating method stubs for interface: " iface = vim.fn.input "impl: generating method stubs for interface: "
vim.cmd "redraw!" vim.cmd "redraw!"
if iface == "" then 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 return
end end
elseif #args == 1 then -- :GoImpl io.Reader elseif #args == 1 then -- :GoImpl io.Reader
@ -60,9 +60,9 @@ function impl.impl(...)
args = cmd_args, args = cmd_args,
on_exit = function(data, retval) on_exit = function(data, retval)
if retval ~= 0 then if retval ~= 0 then
u.notify( u.deferred_notify(
"command '" .. c.impl .. " " .. unpack(cmd_args) .. "' exited with code " .. retval, "command '" .. c.impl .. " " .. unpack(cmd_args) .. "' exited with code " .. retval,
"error" vim.log.levels.ERROR
) )
return return
end end

View file

@ -20,11 +20,11 @@ local function install(pkg)
args = { "install", url }, args = { "install", url },
on_exit = function(_, retval) on_exit = function(_, retval)
if retval ~= 0 then 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 return
end end
u.notify("install " .. url .. " finished", "info ") u.deferred_notify("install " .. url .. " finished", vim.log.levels.INFO)
end, end,
}):start() }):start()
end end

View file

@ -46,14 +46,14 @@ 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
u.notify( u.deferred_notify(
"command '" "command '"
.. c.gomodifytags .. c.gomodifytags
.. " " .. " "
.. unpack(cmd_args) .. unpack(cmd_args)
.. "' exited with code " .. "' exited with code "
.. retval, .. retval,
"error" vim.log.levels.ERROR
) )
return return
end end
@ -70,7 +70,7 @@ local function modify(...)
or tagged["start"] == nil or tagged["start"] == nil
or tagged["start"] == 0 or tagged["start"] == 0
then 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 end
for i, v in ipairs(tagged.lines) do for i, v in ipairs(tagged.lines) do