fix(runner): now it returns output correctly

This commit is contained in:
Smirnov Oleksandr 2023-08-09 12:36:44 +03:00
parent 16b9a5c8f4
commit 4e80f30cb3

View file

@ -2,7 +2,7 @@ local Job = require "plenary.job"
local runner = {}
---@class gopher.RunnerOpts
---@field args string[]
---@field args? string[]
---@field cwd? string?
---@field on_exit? fun(data:string, status:number)
@ -10,15 +10,17 @@ local runner = {}
---@param opts gopher.RunnerOpts
---@return string
function runner.sync(cmd, opts)
local output
local output = ""
Job:new({
command = cmd,
args = opts.args,
cwd = opts.cwd,
on_exit = function(data, status)
vim.schedule(function()
output = data:result()
vim.schedule(function()
if opts.on_exit then
opts.on_exit(output, status)
end
end)
end,
}):sync()