gopher.nvim/lua/gopher/iferr.lua
Smirnov Oleksandr fbf6441f3d
feat: add logger (#64)
* refactor(health): keep in mind new way of health check (#63)

* feat(log): add logger module

* refactor(utils): remove unused code

* refactor(log, utils): get plugin name from config

* refactor(logger): add some type annotations

* refactor(utils): log notifications

* feat: LOGGER™

* feat(config): TYPES

* refactor(log): dont give a thing about var that is not even declared

* feat(log): add easy way to open log

* refactor(log): some types

* update types

* docs: regen

* fix(log): make setting log level by config work

* feat(iferr): write error to log file if occur

* feat(gotests): add logger
2024-06-15 12:18:26 +03:00

26 lines
797 B
Lua

---@toc_entry Iferr
---@tag gopher.nvim-iferr
---@text if you're using `iferr` tool, this module provides a way to automatically insert `if err != nil` check.
---@usage execute `:GoIfErr` near any err variable to insert the check
local c = require "gopher.config"
local log = require "gopher._utils.log"
local iferr = {}
-- That's Lua implementation: github.com/koron/iferr
function iferr.iferr()
local boff = vim.fn.wordcount().cursor_bytes
local pos = vim.fn.getcurpos()[2]
local data = vim.fn.systemlist((c.commands.iferr .. " -pos " .. boff), vim.fn.bufnr "%")
if vim.v.shell_error ~= 0 then
error("iferr failed: " .. data)
log.error("failed. output: " .. data)
end
vim.fn.append(pos, data)
vim.cmd [[silent normal! j=2j]]
vim.fn.setpos(".", pos)
end
return iferr