From 658027ccec6b4bbad10284c4ef018b91d164a5fe Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Thu, 10 Aug 2023 11:48:26 +0300 Subject: [PATCH] refactor: use more currect way of notifying --- lua/gopher/_utils/runner/gocmd.lua | 9 +++++---- lua/gopher/gotests.lua | 7 ++++--- lua/gopher/iferr.lua | 2 +- lua/gopher/impl.lua | 3 +-- lua/gopher/installer.lua | 5 +++-- lua/gopher/struct_tags.lua | 4 ++-- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lua/gopher/_utils/runner/gocmd.lua b/lua/gopher/_utils/runner/gocmd.lua index 2dd6a29..97323f9 100644 --- a/lua/gopher/_utils/runner/gocmd.lua +++ b/lua/gopher/_utils/runner/gocmd.lua @@ -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 diff --git a/lua/gopher/gotests.lua b/lua/gopher/gotests.lua index 94574ad..942fab3 100644 --- a/lua/gopher/gotests.lua +++ b/lua/gopher/gotests.lua @@ -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 diff --git a/lua/gopher/iferr.lua b/lua/gopher/iferr.lua index 3797d25..0898693 100644 --- a/lua/gopher/iferr.lua +++ b/lua/gopher/iferr.lua @@ -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) diff --git a/lua/gopher/impl.lua b/lua/gopher/impl.lua index a337bc3..155d6c2 100644 --- a/lua/gopher/impl.lua +++ b/lua/gopher/impl.lua @@ -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, }) diff --git a/lua/gopher/installer.lua b/lua/gopher/installer.lua index bfabcd9..2994b8a 100644 --- a/lua/gopher/installer.lua +++ b/lua/gopher/installer.lua @@ -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 diff --git a/lua/gopher/struct_tags.lua b/lua/gopher/struct_tags.lua index 16742d8..d31ce4b 100644 --- a/lua/gopher/struct_tags.lua +++ b/lua/gopher/struct_tags.lua @@ -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(