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

View file

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

View file

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

View file

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

View file

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

View file

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