From 8b6566df74abca62f99059390c973a3704eaff17 Mon Sep 17 00:00:00 2001 From: Valentin Uveges Date: Wed, 25 Jun 2025 16:07:32 +0300 Subject: [PATCH] fix: reset chan when caling output_panel.clear() --- lua/neotest/consumers/output_panel/init.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lua/neotest/consumers/output_panel/init.lua b/lua/neotest/consumers/output_panel/init.lua index 9a2b8ad1..359278f9 100644 --- a/lua/neotest/consumers/output_panel/init.lua +++ b/lua/neotest/consumers/output_panel/init.lua @@ -7,6 +7,7 @@ local OutputPanel = require("neotest.consumers.output_panel.panel") local panel local neotest = {} +local chan ---@toc_entry Output Panel Consumer ---@text @@ -14,22 +15,21 @@ local neotest = {} ---@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 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 @@ -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)