From 701f5352c839cfcd20774d1bb1519e732db718f0 Mon Sep 17 00:00:00 2001 From: Manish Suthar Date: Sat, 19 Apr 2025 01:56:50 +0530 Subject: [PATCH] fix(validation): Ensure If the erminal buffer is excluded from #buffers and #buffer This prevents unsolicited text from being included in the CopilotChat context window. --- lua/CopilotChat/utils.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lua/CopilotChat/utils.lua b/lua/CopilotChat/utils.lua index a9201239..1be2504b 100644 --- a/lua/CopilotChat/utils.lua +++ b/lua/CopilotChat/utils.lua @@ -210,10 +210,15 @@ function M.kv_list(tbl) end --- Check if a buffer is valid +--- Check if the buffer is not a terminal ---@param bufnr number? The buffer number ---@return boolean function M.buf_valid(bufnr) - return bufnr and vim.api.nvim_buf_is_valid(bufnr) and vim.api.nvim_buf_is_loaded(bufnr) or false + return bufnr + and vim.api.nvim_buf_is_valid(bufnr) + and vim.api.nvim_buf_is_loaded(bufnr) + and vim.bo[bufnr].buftype ~= 'terminal' + or false end --- Check if file paths are the same