Skip to content

Commit

Permalink
fix: resolve history bug with custom hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
frankroeder committed Sep 14, 2024
1 parent e315601 commit 0db1e3b
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lua/parrot/chat_handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0db1e3b

Please sign in to comment.