Skip to content

Commit

Permalink
feat(output): allow disabling auto-close
Browse files Browse the repository at this point in the history
See #136
  • Loading branch information
rcarriga committed Oct 31, 2022
1 parent beca3c6 commit 2e975ae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
1 change: 1 addition & 0 deletions doc/neotest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ window will be used
{position_id} `(string)` Open output for position with this ID, opens nearest
position if not given
{adapter} `(string)` Adapter ID, defaults to first found with matching position
{auto_close} `(boolean)` Close output window when leaving it, or when cursor moves outside of window


==============================================================================
Expand Down
47 changes: 24 additions & 23 deletions lua/neotest/consumers/output.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,31 @@ local function open_output(result, opts)
pcall(vim.fn.chanclose, chan)
win = nil
end
if opts.open_win then
local cur_win = vim.api.nvim_get_current_win()
win = opts.open_win({ width = width, height = height })
if not win then
win = vim.api.nvim_get_current_win()
end
vim.api.nvim_create_autocmd("WinClosed", {
pattern = tostring(win),
callback = on_close,
})
vim.api.nvim_win_set_buf(win, buf)
if opts.enter then
vim.api.nvim_set_current_win(win)
else
vim.api.nvim_set_current_win(cur_win)

opts.open_win = opts.open_win
or function(win_opts)
return lib.ui.float.open({
width = win_opts.width,
height = win_opts.height,
buffer = buf,
auto_close = opts.auto_close,
}).win_id
end

local cur_win = vim.api.nvim_get_current_win()

win = opts.open_win({ width = width, height = height }) or vim.api.nvim_get_current_win()

vim.api.nvim_create_autocmd("WinClosed", {
pattern = tostring(win),
callback = on_close,
})
vim.api.nvim_win_set_buf(win, buf)

if opts.enter then
vim.api.nvim_set_current_win(win)
else
local float = lib.ui.float.open({
width = width,
height = height,
buffer = buf,
enter = opts.enter,
})
float:listen("close", on_close)
win = float.win_id
vim.api.nvim_set_current_win(cur_win)
end

vim.api.nvim_buf_set_option(buf, "filetype", "neotest-output")
Expand Down Expand Up @@ -152,6 +152,7 @@ end
---@field position_id string Open output for position with this ID, opens nearest
--- position if not given
---@field adapter string Adapter ID, defaults to first found with matching position
---@field auto_close boolean Close output window when leaving it, or when cursor moves outside of window
function neotest.output.open(opts)
opts = opts or {}
if win then
Expand Down
2 changes: 1 addition & 1 deletion lua/neotest/lib/ui/float.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function M.open(settings)
---@type neotest.Float
local win = Float:new(win_id, position)

if opts.auto_close ~= false then
if settings.auto_close ~= false then
local function auto_close()
if not win:close(false) then
vim.api.nvim_create_autocmd(
Expand Down

0 comments on commit 2e975ae

Please sign in to comment.