From 4e80f30cb34312e0f6eb12b27263e4b99657d32a Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Wed, 9 Aug 2023 12:36:44 +0300 Subject: [PATCH] fix(runner): now it returns output correctly --- lua/gopher/_utils/runner.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lua/gopher/_utils/runner.lua b/lua/gopher/_utils/runner.lua index fdf5d35..5ee1008 100644 --- a/lua/gopher/_utils/runner.lua +++ b/lua/gopher/_utils/runner.lua @@ -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) + output = data:result() vim.schedule(function() - output = data:result() - opts.on_exit(output, status) + if opts.on_exit then + opts.on_exit(output, status) + end end) end, }):sync()