From edffaffab74f975ed8aa0e1b967aa1b417bd9a8b Mon Sep 17 00:00:00 2001 From: "Schmidt, Tibor" Date: Tue, 27 Feb 2024 23:17:03 +0100 Subject: [PATCH 1/5] fix: don't list toggle/popup bufs (resolves: #111) --- lua/gp/init.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lua/gp/init.lua b/lua/gp/init.lua index 9eab3d6..1352541 100644 --- a/lua/gp/init.lua +++ b/lua/gp/init.lua @@ -332,7 +332,7 @@ end ---@param buf number | nil # buffer number ---@param title string # title of the popup ---@param size_func function # size_func(editor_width, editor_height) -> width, height, row, col ----@param opts table # options - gid=nul, on_leave=false, keep_buf=false +---@param opts table # options - gid=nul, on_leave=false, persist=false ---@param style table # style - border="single" ---returns table with buffer, window, close function, resize function _H.create_popup = function(buf, title, size_func, opts, style) @@ -341,7 +341,7 @@ _H.create_popup = function(buf, title, size_func, opts, style) local border = style.border or "single" -- create buffer - buf = buf or vim.api.nvim_create_buf(not not opts.persist, not opts.persist) + buf = buf or vim.api.nvim_create_buf(false, not opts.persist) -- setting to the middle of the editor local options = { @@ -394,7 +394,7 @@ _H.create_popup = function(buf, title, size_func, opts, style) if win and vim.api.nvim_win_is_valid(win) then vim.api.nvim_win_close(win, true) end - if opts.keep_buf then + if opts.persist then return end if vim.api.nvim_buf_is_valid(buf) then @@ -1559,7 +1559,7 @@ M.open_buf = function(file_name, target, kind, toggle) local wh = h - (top + bottom) return ww, wh, top, (w - ww) / 2 end, - { on_leave = false, escape = false, persist = true, keep_buf = true }, + { on_leave = false, escape = false, persist = true }, { border = M.config.style_popup_border or "single" } ) @@ -1613,6 +1613,8 @@ M.open_buf = function(file_name, target, kind, toggle) return buf end + vim.api.nvim_buf_set_option(buf, "buflisted", false) + if target == M.BufTarget.split or target == M.BufTarget.vsplit then close = function() if vim.api.nvim_win_is_valid(win) then From 36c2dce5f7a65798b93c0d0f177d20a40f471fe9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 27 Feb 2024 22:22:17 +0000 Subject: [PATCH 2/5] chore: auto-generate vimdoc --- doc/gp.nvim.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/gp.nvim.txt b/doc/gp.nvim.txt index 97d715c..94aaeab 100644 --- a/doc/gp.nvim.txt +++ b/doc/gp.nvim.txt @@ -1,4 +1,4 @@ -*gp.nvim.txt* For NVIM v0.8.0 Last change: 2024 February 03 +*gp.nvim.txt* For NVIM v0.8.0 Last change: 2024 February 27 ============================================================================== Table of Contents *gp.nvim-table-of-contents* From fed4875594076bcc639b0a49afb9c059cff06364 Mon Sep 17 00:00:00 2001 From: "Schmidt, Tibor" Date: Tue, 27 Feb 2024 23:57:48 +0100 Subject: [PATCH 3/5] fix: deprecated opt healthcheck (resolves #105) --- lua/gp/health.lua | 2 +- lua/gp/init.lua | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lua/gp/health.lua b/lua/gp/health.lua index 201143b..719ec3b 100644 --- a/lua/gp/health.lua +++ b/lua/gp/health.lua @@ -69,7 +69,7 @@ function M.check() end end - if #gp._deprecated > 0 then + if gp._deprecated and #gp._deprecated > 0 then local msg = "deprecated config option(s) in setup():" for _, v in ipairs(gp._deprecated) do msg = msg .. "\n\n- " .. v.msg diff --git a/lua/gp/init.lua b/lua/gp/init.lua index 1352541..52d53fe 100644 --- a/lua/gp/init.lua +++ b/lua/gp/init.lua @@ -31,6 +31,7 @@ local M = { _handles = {}, -- handles for running processes _queries = {}, -- table of latest queries _state = {}, -- table of state variables + _deprecated = {}, -- table of deprecated options agents = {}, -- table of agents image_agents = {}, -- table of image agents cmd = {}, -- default command functions @@ -699,8 +700,6 @@ M.setup = function(opts) opts[tbl] = nil end - -- merge user opts to M.config - M._deprecated = {} for k, v in pairs(opts) do if deprecated[k] then table.insert(M._deprecated, { name = k, msg = deprecated[k], value = v }) From a0ab7531f21027b0b0582381f02c46b8cda6e8d4 Mon Sep 17 00:00:00 2001 From: "Schmidt, Tibor" Date: Tue, 27 Feb 2024 23:59:51 +0100 Subject: [PATCH 4/5] chore: fmt --- lua/gp/init.lua | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/lua/gp/init.lua b/lua/gp/init.lua index 52d53fe..a2656d8 100644 --- a/lua/gp/init.lua +++ b/lua/gp/init.lua @@ -1545,22 +1545,18 @@ M.open_buf = function(file_name, target, kind, toggle) if target == M.BufTarget.popup then local old_buf = M._H.get_buffer(file_name) - buf, win, close, _ = M._H.create_popup( - old_buf, - M._Name .. " Popup", - function(w, h) - local top = M.config.style_popup_margin_top or 2 - local bottom = M.config.style_popup_margin_bottom or 8 - local left = M.config.style_popup_margin_left or 1 - local right = M.config.style_popup_margin_right or 1 - local max_width = M.config.style_popup_max_width or 160 - local ww = math.min(w - (left + right), max_width) - local wh = h - (top + bottom) - return ww, wh, top, (w - ww) / 2 - end, - { on_leave = false, escape = false, persist = true }, - { border = M.config.style_popup_border or "single" } - ) + buf, win, close, _ = M._H.create_popup(old_buf, M._Name .. " Popup", function(w, h) + local top = M.config.style_popup_margin_top or 2 + local bottom = M.config.style_popup_margin_bottom or 8 + local left = M.config.style_popup_margin_left or 1 + local right = M.config.style_popup_margin_right or 1 + local max_width = M.config.style_popup_max_width or 160 + local ww = math.min(w - (left + right), max_width) + local wh = h - (top + bottom) + return ww, wh, top, (w - ww) / 2 + end, { on_leave = false, escape = false, persist = true }, { + border = M.config.style_popup_border or "single", + }) if not toggle then M._toggle_add(M._toggle_kind.popup, { win = win, buf = buf, close = close }) From a8bf93bd980a19681353bb079e11e2ebb8bb5207 Mon Sep 17 00:00:00 2001 From: "Schmidt, Tibor" Date: Wed, 28 Feb 2024 00:22:02 +0100 Subject: [PATCH 5/5] chore: better errors for chat checks (issue: #104) --- lua/gp/init.lua | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lua/gp/init.lua b/lua/gp/init.lua index a2656d8..d66e223 100644 --- a/lua/gp/init.lua +++ b/lua/gp/init.lua @@ -806,7 +806,7 @@ M.setup = function(opts) if cmd == "Agent" then local buf = vim.api.nvim_get_current_buf() local file_name = vim.api.nvim_buf_get_name(buf) - if M.is_chat(buf, file_name) then + if M.not_chat(buf, file_name) == nil then return M._chat_agents end return M._command_agents @@ -1372,28 +1372,31 @@ M.prep_md = function(buf) M._H.feedkeys("", "xn") end -M.is_chat = function(buf, file_name) +---@param buf number # buffer number +---@param file_name string # file name +---@return string | nil # reason for not being a chat or nil if it is a chat +M.not_chat = function(buf, file_name) if not _H.starts_with(file_name, M.config.chat_dir) then - return false + return "not in chat directory (" .. M.config.chat_dir .. ")" end local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false) if #lines < 4 then - return false + return "file too short" end if not lines[1]:match("^# ") then - return false + return "missing topic header" end if not (lines[3]:match("^- file: ") or lines[4]:match("^- file: ")) then - return false + return "missing file header" end - return true + return nil end M.prep_chat = function(buf, file_name) - if not M.is_chat(buf, file_name) then + if M.not_chat(buf, file_name) then return end @@ -1834,8 +1837,9 @@ M.chat_respond = function(params) -- check if file looks like a chat file local file_name = vim.api.nvim_buf_get_name(buf) - if not M.is_chat(buf, file_name) then - M.warning("File " .. vim.inspect(file_name) .. " does not look like a chat file") + local reason = M.not_chat(buf, file_name) + if reason then + M.warning("File " .. vim.inspect(file_name) .. " does not look like a chat file: " .. vim.inspect(reason)) return end @@ -2374,7 +2378,7 @@ M.cmd.Agent = function(params) local buf = vim.api.nvim_get_current_buf() local file_name = vim.api.nvim_buf_get_name(buf) - local is_chat = M.is_chat(buf, file_name) + local is_chat = M.not_chat(buf, file_name) == nil if is_chat and M.agents[agent_name].chat then M._state.chat_agent = agent_name M.info("Chat agent: " .. M._state.chat_agent) @@ -2393,7 +2397,7 @@ end M.cmd.NextAgent = function() local buf = vim.api.nvim_get_current_buf() local file_name = vim.api.nvim_buf_get_name(buf) - local is_chat = M.is_chat(buf, file_name) + local is_chat = M.not_chat(buf, file_name) == nil local current_agent, agent_list if is_chat then