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

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)
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]

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