2021-04-23 06:31:00 +00:00
|
|
|
-- local ts_utils = require 'nvim-treesitter.ts_utils'
|
2021-07-07 05:56:22 +00:00
|
|
|
local utils = require("go.utils")
|
2022-06-01 11:29:13 +00:00
|
|
|
local vfn = vim.fn
|
2021-04-23 06:31:00 +00:00
|
|
|
|
|
|
|
local iferr = "iferr"
|
2022-06-01 11:29:13 +00:00
|
|
|
local run = function()
|
2021-04-23 06:31:00 +00:00
|
|
|
require("go.install").install(iferr)
|
|
|
|
|
2022-06-01 11:29:13 +00:00
|
|
|
local byte_offset = vfn.wordcount().cursor_bytes
|
2021-04-23 06:31:00 +00:00
|
|
|
|
2021-07-14 15:01:09 +00:00
|
|
|
local cmd = string.format('iferr -pos %d', byte_offset)
|
|
|
|
|
2022-06-01 11:29:13 +00:00
|
|
|
local data = vfn.systemlist(cmd, vfn.bufnr('%'))
|
2021-07-14 15:01:09 +00:00
|
|
|
|
|
|
|
data = utils.handle_job_data(data)
|
|
|
|
if not data then
|
|
|
|
return
|
|
|
|
end
|
2022-06-28 04:36:30 +00:00
|
|
|
if vim.v.shell_error ~= 0 then
|
|
|
|
utils.warn("iferr failed" .. vim.inspect(data))
|
|
|
|
return
|
|
|
|
end
|
2021-07-14 15:01:09 +00:00
|
|
|
|
2022-06-01 11:29:13 +00:00
|
|
|
local pos = vfn.getcurpos()[2]
|
|
|
|
vfn.append(pos, data)
|
2021-07-14 15:01:09 +00:00
|
|
|
|
|
|
|
vim.cmd('silent normal! j=2j')
|
2022-06-01 11:29:13 +00:00
|
|
|
vfn.setpos('.', pos)
|
2021-07-14 15:01:09 +00:00
|
|
|
vim.cmd('silent normal! 4j')
|
|
|
|
--
|
|
|
|
|
2021-04-23 06:31:00 +00:00
|
|
|
end
|
|
|
|
return {run = run}
|