diff --git a/lua/gopher/struct_tags.lua b/lua/gopher/struct_tags.lua index 690eae1..0ffe114 100644 --- a/lua/gopher/struct_tags.lua +++ b/lua/gopher/struct_tags.lua @@ -1,5 +1,5 @@ local ts_utils = require "gopher._utils.ts" -local Job = require "plenary.job" +local r = require "gopher._utils.runner" local c = require("gopher.config").commands local u = require "gopher._utils" local struct_tags = {} @@ -39,31 +39,17 @@ local function modify(...) table.insert(cmd_args, "json") end - -- get result of "gomodifytags" works - local res_data - Job:new({ - command = c.gomodifytags, + local output = r.sync(c.gomodifytags, { args = cmd_args, - on_exit = function(data, retval) - if retval ~= 0 then - u.deferred_notify( - "command '" - .. c.gomodifytags - .. " " - .. unpack(cmd_args) - .. "' exited with code " - .. retval, - vim.log.levels.ERROR - ) - return + on_exit = function(data, status) + if not status == 0 then + error("gotag failed: " .. data, vim.log.levels.ERROR) end - - res_data = data:result() end, - }):sync() + }) -- decode goted value - local tagged = vim.json.decode(table.concat(res_data)) + local tagged = vim.json.decode(table.concat(output)) if tagged.errors ~= nil or tagged.lines == nil @@ -73,10 +59,6 @@ local function modify(...) u.deferred_notify("failed to set tags " .. vim.inspect(tagged), vim.log.levels.ERROR) end - for i, v in ipairs(tagged.lines) do - tagged.lines[i] = u.rtrim(v) - end - -- write goted tags vim.api.nvim_buf_set_lines( 0,