|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
local uv, api = vim.loop, vim.api
|
|
|
|
|
local util = require('go.utils')
|
|
|
|
|
local log = require('go.utils').log
|
|
|
|
|
local util = require("go.utils")
|
|
|
|
|
local log = require("go.utils").log
|
|
|
|
|
local check_same = function(tbl1, tbl2)
|
|
|
|
|
if #tbl1 ~= #tbl2 then
|
|
|
|
|
return
|
|
|
|
@ -22,12 +22,13 @@ local run = function(cmd, opts)
|
|
|
|
|
cmd = vim.split(cmd, split_pattern)
|
|
|
|
|
log(cmd)
|
|
|
|
|
end
|
|
|
|
|
local cmd_str = vim.inspect(cmd)
|
|
|
|
|
local job_options = vim.deepcopy(opts or {})
|
|
|
|
|
job_options.args = job_options.args or {}
|
|
|
|
|
local cmdargs = vim.list_slice(cmd, 2, #cmd) or {}
|
|
|
|
|
|
|
|
|
|
if cmdargs and cmdargs[1] == 'test' and #cmdargs == 3 then
|
|
|
|
|
table.insert(cmdargs, '.' .. util.sep() .. '...')
|
|
|
|
|
if cmdargs and cmdargs[1] == "test" and #cmdargs == 3 then
|
|
|
|
|
table.insert(cmdargs, "." .. util.sep() .. "...")
|
|
|
|
|
log(cmdargs)
|
|
|
|
|
end
|
|
|
|
|
vim.list_extend(cmdargs, job_options.args)
|
|
|
|
@ -48,41 +49,43 @@ local run = function(cmd, opts)
|
|
|
|
|
local winnr = api.nvim_get_current_win()
|
|
|
|
|
local bufnr = api.nvim_get_current_buf()
|
|
|
|
|
|
|
|
|
|
local output_buf = ''
|
|
|
|
|
local output_buf = ""
|
|
|
|
|
local function update_chunk(err, chunk)
|
|
|
|
|
if chunk then
|
|
|
|
|
output_buf = output_buf .. chunk
|
|
|
|
|
local lines = vim.split(output_buf, '\n', true)
|
|
|
|
|
local lines = vim.split(output_buf, "\n", true)
|
|
|
|
|
api.nvim_buf_set_option(bufnr, "modifiable", true)
|
|
|
|
|
api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
|
|
|
|
api.nvim_buf_set_option(bufnr, "modifiable", false)
|
|
|
|
|
api.nvim_buf_set_option(bufnr, "modified", false)
|
|
|
|
|
if api.nvim_win_is_valid(winnr) then
|
|
|
|
|
api.nvim_win_set_cursor(winnr, {#lines, 0})
|
|
|
|
|
api.nvim_win_set_cursor(winnr, { #lines, 0 })
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
update_chunk = vim.schedule_wrap(update_chunk)
|
|
|
|
|
|
|
|
|
|
log("job:", cmd, job_options)
|
|
|
|
|
handle, pid = uv.spawn(cmd, {stdio = {stdin, stdout, stderr}, args = job_options.args},
|
|
|
|
|
function(code, signal) -- on exit
|
|
|
|
|
update_chunk(nil, "Process exited with code " .. code .. " / signal " .. signal)
|
|
|
|
|
stdin:read_stop()
|
|
|
|
|
stdin:close()
|
|
|
|
|
handle, pid = uv.spawn(
|
|
|
|
|
cmd,
|
|
|
|
|
{ stdio = { stdin, stdout, stderr }, args = job_options.args },
|
|
|
|
|
function(code, signal) -- on exit
|
|
|
|
|
update_chunk(nil, cmd_str .. " finished with code " .. code .. " / signal " .. signal)
|
|
|
|
|
stdin:read_stop()
|
|
|
|
|
stdin:close()
|
|
|
|
|
|
|
|
|
|
stdout:read_stop()
|
|
|
|
|
stdout:close()
|
|
|
|
|
handle:close()
|
|
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
stdout:read_stop()
|
|
|
|
|
stdout:close()
|
|
|
|
|
handle:close()
|
|
|
|
|
end
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
api.nvim_buf_attach(bufnr, false, {
|
|
|
|
|
on_detach = function()
|
|
|
|
|
if not handle:is_closing() then
|
|
|
|
|
handle:kill(15)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
-- uv.read_start(stdout, vim.schedule_wrap(on_stdout))
|
|
|
|
@ -95,12 +98,11 @@ local run = function(cmd, opts)
|
|
|
|
|
end)
|
|
|
|
|
stdout:read_start(update_chunk)
|
|
|
|
|
stderr:read_start(update_chunk)
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function make(...)
|
|
|
|
|
local makeprg = vim.api.nvim_buf_get_option(0, "makeprg")
|
|
|
|
|
local args = {...}
|
|
|
|
|
local args = { ... }
|
|
|
|
|
local setup = {}
|
|
|
|
|
if #args > 0 then
|
|
|
|
|
for i, v in ipairs(args) do
|
|
|
|
@ -112,4 +114,4 @@ local function make(...)
|
|
|
|
|
run(makeprg, opts)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return {run = run, make = make}
|
|
|
|
|
return { run = run, make = make }
|
|
|
|
|