Skip to content

Commit 2a4f0ba

Browse files
committed
streaming: flush buffer on new session
1 parent 5049ecc commit 2a4f0ba

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lua/codegpt/api.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local Config = require("codegpt.config")
33
local M = {}
44

55
local CODEGPT_CALLBACK_COUNTER = 0
6+
---@type Job
67
M.current_job = nil
78

89
local status_index = 0

lua/codegpt/ui.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,14 @@ end
134134
local streaming = false
135135
local stream_ui_elem = nil
136136

137+
---@param job Job
137138
function M.popup_stream(job, stream, filetype, bufnr, start_row, start_col, end_row, end_col)
138139
if job ~= nil and job.is_shutdown then
140+
streaming = false
139141
return
140142
end
141143
if not streaming then
144+
buffer = ""
142145
streaming = true
143146
stream_ui_elem = create_window()
144147

@@ -148,18 +151,23 @@ function M.popup_stream(job, stream, filetype, bufnr, start_row, start_col, end_
148151
if not (Config.persistent_override or Config.opts.ui.persistent) then
149152
-- unmount component when cursor leaves buffer
150153
stream_ui_elem:on(event.BufLeave, function()
154+
job:shutdown()
155+
streaming = false
151156
stream_ui_elem:unmount()
152157
end)
153158
end
154159

155160
-- unmount component when key 'q'
156161
stream_ui_elem:map("n", Config.opts.ui.actions.quit, function()
162+
job:shutdown()
163+
streaming = false
157164
stream_ui_elem:unmount()
158165
end, { noremap = true, silent = true })
159166

160167
-- cancel job if actions.cancel is called
161168
stream_ui_elem:map("n", Config.opts.ui.actions.cancel, function()
162169
job:shutdown()
170+
streaming = false
163171
end, { noremap = true, silent = true })
164172

165173
vim.api.nvim_set_option_value("filetype", filetype, { buf = stream_ui_elem.bufnr })

0 commit comments

Comments
 (0)