refactor: use vim.system instead of pleanry (#85)
* refactor!: migrate to vim.system * refactor(gotests): use vim.system * refactor(iferr): use vim.system * refactor(impl): use vim.system * refactor(installer): use vim.system and add sync mode * test: fix gotests' tests * refactor(struct_tags): use vim.system * chore(ci): install all deps explicitly * refactor(installer)!: add sync as an option * docs: update readme
This commit is contained in:
parent
837897a79d
commit
6016ca57d4
16 changed files with 169 additions and 126 deletions
|
|
@ -4,27 +4,33 @@
|
|||
---@usage Execute `:GoIfErr` near any `err` variable to insert the check
|
||||
|
||||
local c = require "gopher.config"
|
||||
local u = require "gopher._utils"
|
||||
local r = require "gopher._utils.runner"
|
||||
local log = require "gopher._utils.log"
|
||||
local iferr = {}
|
||||
|
||||
-- That's Lua implementation: github.com/koron/iferr
|
||||
-- That's Lua implementation: https://github.com/koron/iferr
|
||||
function iferr.iferr()
|
||||
local boff = vim.fn.wordcount().cursor_bytes
|
||||
local curb = vim.fn.wordcount().cursor_bytes
|
||||
local pos = vim.fn.getcurpos()[2]
|
||||
local fpath = vim.fn.expand "%"
|
||||
|
||||
local data = vim.fn.systemlist((c.commands.iferr .. " -pos " .. boff), vim.fn.bufnr "%")
|
||||
if vim.v.shell_error ~= 0 then
|
||||
if string.find(data[1], "no functions at") then
|
||||
vim.print "no function found"
|
||||
log.warn("iferr: no function at " .. boff)
|
||||
local rs = r.sync({ c.commands.iferr, "-pos", curb }, {
|
||||
stdin = u.readfile_joined(fpath),
|
||||
})
|
||||
|
||||
if rs.code ~= 0 then
|
||||
if string.find(rs.stderr, "no functions at") then
|
||||
u.notify("iferr: no function at " .. curb, vim.log.levels.ERROR)
|
||||
log.warn("iferr: no function at " .. curb)
|
||||
return
|
||||
end
|
||||
|
||||
log.error("failed. output: " .. vim.inspect(data))
|
||||
error("iferr failed: " .. vim.inspect(data))
|
||||
log.error("ferr: failed. output: " .. rs.stderr)
|
||||
error("iferr failed: " .. rs.stderr)
|
||||
end
|
||||
|
||||
vim.fn.append(pos, data)
|
||||
vim.fn.append(pos, u.remove_empty_lines(vim.split(rs.stdout, "\n")))
|
||||
vim.cmd [[silent normal! j=2j]]
|
||||
vim.fn.setpos(".", pos)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue