From 13cafc6d224d0d6f4979dd21a43e19a6613bc67f Mon Sep 17 00:00:00 2001 From: XXiaoA Date: Sat, 3 Feb 2024 11:56:46 +0800 Subject: [PATCH 1/4] fix: set feedkeys mode to `xn` (resolve #100) --- lua/gp/init.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lua/gp/init.lua b/lua/gp/init.lua index 83572b2..24b1eac 100644 --- a/lua/gp/init.lua +++ b/lua/gp/init.lua @@ -1367,7 +1367,7 @@ M.prep_md = function(buf) -- ensure normal mode vim.api.nvim_command("stopinsert") - M._H.feedkeys("", "x") + M._H.feedkeys("", "xn") end M.is_chat = function(buf, file_name) @@ -1432,7 +1432,7 @@ M.prep_chat = function(buf, file_name) vim.api.nvim_command(M.config.cmd_prefix .. rc.command) -- go to normal mode vim.api.nvim_command("stopinsert") - M._H.feedkeys("", "x") + M._H.feedkeys("", "xn") end, rc.comment) else _H.set_keymap({ buf }, mode, rc.shortcut, ":'<,'>" .. cmd, rc.comment) @@ -1570,7 +1570,7 @@ M.open_buf = function(file_name, target, kind, toggle) vim.api.nvim_command("silent file " .. file_name) else -- move cursor to the beginning of the file and scroll to the end - M._H.feedkeys("ggG", "x") + M._H.feedkeys("ggG", "xn") end -- delete whitespace lines at the end of the file @@ -1699,7 +1699,7 @@ M.new_chat = function(params, model, system_prompt, toggle) if params.range == 2 then M.append_selection(params, cbuf, buf) end - M._H.feedkeys("G", "x") + M._H.feedkeys("G", "xn") return buf end @@ -1785,7 +1785,7 @@ M.cmd.ChatPaste = function(params) buf = win_found and buf or M.open_buf(last, target, M._toggle_kind.chat, true) M.append_selection(params, cbuf, buf) - M._H.feedkeys("G", "x") + M._H.feedkeys("G", "xn") end M.cmd.ChatDelete = function() @@ -2479,7 +2479,7 @@ M.cmd.Context = function(params) M.append_selection(params, cbuf, buf) end - M._H.feedkeys("G", "x") + M._H.feedkeys("G", "xn") end M.Prompt = function(params, target, prompt, model, template, system_template, whisper) @@ -2657,7 +2657,7 @@ M.Prompt = function(params, target, prompt, model, template, system_template, wh table.insert(messages, { role = "user", content = user_prompt }) -- cancel possible visual mode before calling the model - M._H.feedkeys("", "x") + M._H.feedkeys("", "xn") local cursor = true if not M.config.command_auto_select_response then From 66690de8e5732a81adbadbf7ffb6d2ddabdcf85c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 3 Feb 2024 08:48:11 +0000 Subject: [PATCH 2/4] 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 09c6016..97d715c 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 January 25 +*gp.nvim.txt* For NVIM v0.8.0 Last change: 2024 February 03 ============================================================================== Table of Contents *gp.nvim-table-of-contents* From 816cd34c07ade92797edf3bda4d9207a40898ab8 Mon Sep 17 00:00:00 2001 From: Marco Mayer Date: Fri, 2 Feb 2024 10:26:58 +0100 Subject: [PATCH 3/4] remote \n from info logs to avoid needing user input With \n neovim waits for user-input (press Enter) on messages which can be annoying. Removing it fixes this. --- lua/gp/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/gp/init.lua b/lua/gp/init.lua index 24b1eac..d351311 100644 --- a/lua/gp/init.lua +++ b/lua/gp/init.lua @@ -531,7 +531,7 @@ end M._log = function(msg, kind, history) vim.schedule(function() vim.api.nvim_echo({ - { M._Name .. ": " .. msg .. "\n", kind }, + { M._Name .. ": " .. msg, kind }, }, history, {}) end) end From d660d9be8d871027c5135c961e33cebb72745227 Mon Sep 17 00:00:00 2001 From: Marco Mayer Date: Fri, 2 Feb 2024 10:27:51 +0100 Subject: [PATCH 4/4] check if state file exists before trying to open it Fixes an issue with an warning popping up on new installations if the state file does not exist. --- lua/gp/init.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lua/gp/init.lua b/lua/gp/init.lua index d351311..9eab3d6 100644 --- a/lua/gp/init.lua +++ b/lua/gp/init.lua @@ -887,7 +887,10 @@ end M.refresh_state = function() local state_file = M.config.state_dir .. "/state.json" - local state = M.file_to_table(state_file) or {} + local state = {} + if vim.fn.filereadable(state_file) ~= 0 then + state = M.file_to_table(state_file) or {} + end M._state.chat_agent = M._state.chat_agent or state.chat_agent or nil if M._state.chat_agent == nil or not M.agents[M._state.chat_agent] then