Skip to content

Commit

Permalink
feat(strategies/integrated): async write
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarriga committed Jul 4, 2022
1 parent b8c66b0 commit 8555ca5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
10 changes: 6 additions & 4 deletions lua/neotest/client/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,11 @@ function NeotestClient:_update_positions(path, args)
-- If existing tree then we have to find the point to merge the trees and update that path rather than trying to
-- merge an orphan. This happens when a whole new directory is found (e.g. renamed an existing one).
local existing_root = self:get_position(nil, { adapter = adapter_id })
while existing_root
and vim.startswith(path, existing_root:data().path)
and not self:get_position(path, { adapter = adapter_id }) do
while
existing_root
and vim.startswith(path, existing_root:data().path)
and not self:get_position(path, { adapter = adapter_id })
do
path = lib.files.parent(path)
if not vim.startswith(path, existing_root:data().path) then
return
Expand Down Expand Up @@ -383,7 +385,7 @@ end
function NeotestClient:_update_adapters(path)
local adapters_with_root = lib.files.is_dir(path)
and self._adapter_group:adapters_with_root_dir(path)
or {}
or {}
local adapters_with_bufs = self._adapter_group:adapters_matching_open_bufs()
local found = {}
for _, adapter in pairs(self._adapters) do
Expand Down
27 changes: 16 additions & 11 deletions lua/neotest/client/strategies/integrated/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,34 @@ return function(spec)
local unread_data = ""
local attach_win, attach_buf, attach_chan
local output_path = async.fn.tempname()
-- TODO: Resolve permissions issues with opening file with luv
local output_file = assert(io.open(output_path, "w"))
local open_err, output_fd = async.uv.fs_open(output_path, "w", 438)
assert(not open_err, open_err)
local success, job = pcall(async.fn.jobstart, command, {
cwd = cwd,
env = env,
pty = true,
height = spec.strategy.height,
width = spec.strategy.width,
on_stdout = function(_, data)
data = table.concat(data, "\n")
unread_data = unread_data .. data
output_file:write(data)
if attach_chan then
async.api.nvim_chan_send(attach_chan, unread_data)
unread_data = ""
end
async.run(function()
data = table.concat(data, "\n")
unread_data = unread_data .. data
local write_err, _ = async.uv.fs_write(output_fd, data)
assert(not write_err, write_err)
if attach_chan then
async.api.nvim_chan_send(attach_chan, unread_data)
unread_data = ""
end
end)
end,
on_exit = function(_, code)
result_code = code
finish_cond:notify_all()
end,
})
if not success then
output_file:write(job)
local write_err, _ = async.uv.fs_write(output_fd, job)
assert(not write_err, write_err)
result_code = 1
finish_cond:notify_all()
end
Expand Down Expand Up @@ -86,7 +90,8 @@ return function(spec)
if result_code == nil then
finish_cond:wait()
end
output_file:close()
local close_err = async.uv.fs_close(output_fd)
assert(not close_err, close_err)
pcall(async.fn.chanclose, job)
if attach_win then
attach_win:listen("close", function()
Expand Down

0 comments on commit 8555ca5

Please sign in to comment.