diff --git a/lua/parrot/chat_handler.lua b/lua/parrot/chat_handler.lua index 81f69e2..6af10ac 100644 --- a/lua/parrot/chat_handler.lua +++ b/lua/parrot/chat_handler.lua @@ -274,18 +274,10 @@ function ChatHandler:prepare_commands() self.options.command_prompt_prefix_template, { ["{{llm}}"] = self:get_model("command").name } ) - self:prompt(params, target, model_obj, cmd_prefix, utils.trim(template)) + self:prompt(params, target, model_obj, cmd_prefix, utils.trim(template), true) end self.commands[command] = command self:addCommand(command, function(params) - if command ~= "Retry" then - self.history = { - last_selection = nil, - last_command = nil, - last_line1 = nil, - last_line2 = nil, - } - end cmd(params) end) end @@ -1048,15 +1040,25 @@ function ChatHandler:retry(params) else logger.error("Invalid last target" .. self.history.last_target) end - self:prompt(params, self.history.last_target, model_obj, nil, utils.trim(template)) + self:prompt(params, self.history.last_target, model_obj, nil, utils.trim(template), false) end -function ChatHandler:prompt(params, target, model_obj, prompt, template) +function ChatHandler:prompt(params, target, model_obj, prompt, template, reset_history) -- enew, new, vnew, tabnew should be resolved into table if type(target) == "function" then target = target() end + logger.debug("ChatHandler:prompt - `reset_history`: " .. vim.inspect(reset_history)) + if reset_history == nil or reset_history then + self.history = { + last_selection = nil, + last_command = nil, + last_line1 = nil, + last_line2 = nil, + } + end + target = target or ui.Target.enew() -- get current buffer @@ -1123,6 +1125,7 @@ function ChatHandler:prompt(params, target, model_obj, prompt, template) local callback = function(command) if self.history.last_command then + logger.debug("LAST COMMAND in use " .. self.history.last_command) command = self.history.last_command end -- dummy handler