refactor: use more currect way of notifying

This commit is contained in:
Smirnov Oleksandr 2023-08-10 11:48:26 +03:00
parent e2ef9dbcd7
commit 658027ccec
6 changed files with 16 additions and 14 deletions

View file

@ -1,5 +1,6 @@
local r = require "gopher._utils.runner" local r = require "gopher._utils.runner"
local c = require("gopher.config").commands local c = require("gopher.config").commands
local u = require "gopher._utils"
local gocmd = {} local gocmd = {}
---@param args string[] ---@param args string[]
@ -27,7 +28,7 @@ end
---@return string[]|nil ---@return string[]|nil
function gocmd.run(subcmd, args) function gocmd.run(subcmd, args)
if #args == 0 then if #args == 0 then
error("please provice any arguments", vim.log.levels.ERROR) error "please provice any arguments"
end end
if subcmd == "get" then if subcmd == "get" then
@ -41,10 +42,10 @@ function gocmd.run(subcmd, args)
return r.sync(c.go, { return r.sync(c.go, {
args = { subcmd, unpack(args) }, args = { subcmd, unpack(args) },
on_exit = function(data, status) on_exit = function(data, status)
if not status == 0 then if status ~= 0 then
error("gocmd failed: " .. data, vim.log.levels.ERROR) error("gocmd failed: " .. data)
end end
vim.notify(c.go .. " " .. subcmd .. " successful runned", vim.log.levels.INFO) u.notify(c.go .. " " .. subcmd .. " successful runned")
end, end,
}) })
end end

View file

@ -1,6 +1,7 @@
local c = require("gopher.config").commands local c = require("gopher.config").commands
local ts_utils = require "gopher._utils.ts" local ts_utils = require "gopher._utils.ts"
local r = require "gopher._utils.runner" local r = require "gopher._utils.runner"
local u = require "gopher._utils"
local gotests = {} local gotests = {}
---@param args table ---@param args table
@ -12,10 +13,10 @@ local function add_test(args)
args = args, args = args,
on_exit = function(data, status) on_exit = function(data, status)
if not status == 0 then if not status == 0 then
error("gotests failed: " .. data, vim.log.levels.ERROR) error("gotests failed: " .. data)
end end
vim.notify("unit test(s) generated", vim.log.levels.INFO) u.notify "unit test(s) generated"
end, end,
}) })
end end
@ -24,7 +25,7 @@ end
function gotests.func_test() function gotests.func_test()
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
vim.notify("cursor on func/method and execute the command again", vim.log.levels.WARN) u.notify("cursor on func/method and execute the command again", vim.log.levels.WARN)
return return
end end

View file

@ -8,7 +8,7 @@ function iferr.iferr()
local data = vim.fn.systemlist((c.iferr .. " -pos " .. boff), vim.fn.bufnr "%") local data = vim.fn.systemlist((c.iferr .. " -pos " .. boff), vim.fn.bufnr "%")
if vim.v.shell_error ~= 0 then if vim.v.shell_error ~= 0 then
error("iferr failed: " .. data, vim.log.levels.ERROR) error("iferr failed: " .. data)
end end
vim.fn.append(pos, data) vim.fn.append(pos, data)

View file

@ -56,8 +56,7 @@ function impl.impl(...)
}, },
on_exit = function(data, status) on_exit = function(data, status)
if not status == 0 then if not status == 0 then
error("impl failed: " .. data, vim.log.levels.ERROR) error("impl failed: " .. data)
return
end end
end, end,
}) })

View file

@ -1,5 +1,6 @@
local c = require("gopher.config").commands local c = require("gopher.config").commands
local r = require "gopher._utils.runner" local r = require "gopher._utils.runner"
local u = require "gopher._utils"
local installer = {} local installer = {}
local urls = { local urls = {
@ -17,10 +18,10 @@ local function install(pkg)
args = { "install", url }, args = { "install", url },
on_exit = function(data, status) on_exit = function(data, status)
if not status == 0 then if not status == 0 then
error("go install failed: " .. data, vim.log.levels.ERROR) error("go install failed: " .. data)
return return
end end
vim.notify("installed: " .. url, vim.log.levels.INFO) u.notify("installed: " .. url)
end, end,
}) })
end end

View file

@ -42,7 +42,7 @@ local function modify(...)
args = cmd_args, args = cmd_args,
on_exit = function(data, status) on_exit = function(data, status)
if not status == 0 then if not status == 0 then
error("gotag failed: " .. data, vim.log.levels.ERROR) error("gotag failed: " .. data)
end end
end, end,
}) })
@ -55,7 +55,7 @@ local function modify(...)
or tagged["start"] == nil or tagged["start"] == nil
or tagged["start"] == 0 or tagged["start"] == 0
then then
error("failed to set tags " .. vim.inspec(tagged), vim.log.levels.ERROR) error("failed to set tags " .. vim.inspec(tagged))
end end
vim.api.nvim_buf_set_lines( vim.api.nvim_buf_set_lines(