Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lua/neotest/consumers/output_panel/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ local OutputPanel = require("neotest.consumers.output_panel.panel")
local panel

local neotest = {}
local chan

---@toc_entry Output Panel Consumer
---@text
--- A consumer that streams all output of tests to a terminal window.
---@class neotest.consumers.output_panel
neotest.output_panel = {}

local channel_is_valid = function(chan_id)
return chan_id and pcall(nio.api.nvim_chan_send, chan_id, "\n")
end

---@param client neotest.Client
---@private
local init = function(client)
panel = OutputPanel(client)

local chan
---@param results table<string, neotest.Result>
client.listeners.results = function(adapter_id, results, partial)
if partial then
return
end

local channel_is_valid = function(chan_id)
return chan_id and pcall(vim.api.nvim_chan_send, chan_id, "\n")
end

if not channel_is_valid(chan) then
chan = lib.ui.open_term(panel.win:buffer())
-- neovim sometimes adds random blank lines when creating a terminal buffer
Expand Down Expand Up @@ -103,6 +103,11 @@ end
--- lua require("neotest").output_panel.clear()
--- <
function neotest.output_panel.clear()
if channel_is_valid(chan) then
vim.fn.chanclose(chan)
chan = lib.ui.open_term(panel.win:buffer())
end

nio.api.nvim_buf_set_option(panel.win:buffer(), "modifiable", true)
nio.api.nvim_buf_set_lines(panel.win:buffer(), 0, -1, false, {})
nio.api.nvim_buf_set_option(panel.win:buffer(), "modifiable", false)
Expand Down
Loading