From 6e70be0ef9a4ab94a2480f51b0483bc2ba3c6346 Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Wed, 19 Jul 2023 23:20:41 +0300 Subject: [PATCH] fix: use new _utils api --- lua/gopher/_utils/commands.lua | 19 +++++++++++-------- lua/gopher/_utils/ts/init.lua | 8 ++++---- lua/gopher/_utils/ts/nodes.lua | 10 ++++++++-- lua/gopher/gotests.lua | 8 ++++---- lua/gopher/iferr.lua | 2 +- lua/gopher/impl.lua | 8 ++++---- lua/gopher/installer.lua | 4 ++-- lua/gopher/struct_tags.lua | 6 +++--- 8 files changed, 37 insertions(+), 28 deletions(-) diff --git a/lua/gopher/_utils/commands.lua b/lua/gopher/_utils/commands.lua index 33926a4..447a3af 100644 --- a/lua/gopher/_utils/commands.lua +++ b/lua/gopher/_utils/commands.lua @@ -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 diff --git a/lua/gopher/_utils/ts/init.lua b/lua/gopher/_utils/ts/init.lua index ee24f49..f7ead56 100644 --- a/lua/gopher/_utils/ts/init.lua +++ b/lua/gopher/_utils/ts/init.lua @@ -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] diff --git a/lua/gopher/_utils/ts/nodes.lua b/lua/gopher/_utils/ts/nodes.lua index 87286a2..42c1812 100644 --- a/lua/gopher/_utils/ts/nodes.lua +++ b/lua/gopher/_utils/ts/nodes.lua @@ -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 diff --git a/lua/gopher/gotests.lua b/lua/gopher/gotests.lua index d5422dd..cf9a0f1 100644 --- a/lua/gopher/gotests.lua +++ b/lua/gopher/gotests.lua @@ -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 diff --git a/lua/gopher/iferr.lua b/lua/gopher/iferr.lua index 24b3786..a8b75e5 100644 --- a/lua/gopher/iferr.lua +++ b/lua/gopher/iferr.lua @@ -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 diff --git a/lua/gopher/impl.lua b/lua/gopher/impl.lua index 64352e3..6eddc0f 100644 --- a/lua/gopher/impl.lua +++ b/lua/gopher/impl.lua @@ -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 diff --git a/lua/gopher/installer.lua b/lua/gopher/installer.lua index cfe3e78..99aac4b 100644 --- a/lua/gopher/installer.lua +++ b/lua/gopher/installer.lua @@ -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 diff --git a/lua/gopher/struct_tags.lua b/lua/gopher/struct_tags.lua index 5b951c9..690eae1 100644 --- a/lua/gopher/struct_tags.lua +++ b/lua/gopher/struct_tags.lua @@ -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