Skip to content

Commit e33c777

Browse files
committed
fix: improve history updates safety
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
1 parent 7ba905e commit e33c777

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

lua/CopilotChat/client.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,8 @@ function Client:ask(prompt, opts)
456456

457457
local history = {}
458458
if opts.load_history then
459-
history = self.history
460-
if self.memory and self.memory.last_summarized_index then
461-
history = vim.list_slice(history, self.memory.last_summarized_index + 1)
462-
end
459+
history =
460+
vim.list_slice(self.history, self.memory and (self.memory.last_summarized_index + 1) or 1)
463461
end
464462

465463
local references = utils.ordered_map()

lua/CopilotChat/config/mappings.lua

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -476,16 +476,6 @@ return {
476476
table.insert(lines, '')
477477
end
478478

479-
if client.memory then
480-
table.insert(lines, '**Memory**')
481-
table.insert(lines, '```')
482-
for _, line in ipairs(vim.split(vim.trim(client.memory.content), '\n')) do
483-
table.insert(lines, line)
484-
end
485-
table.insert(lines, '```')
486-
table.insert(lines, '')
487-
end
488-
489479
copilot.chat:overlay({
490480
text = vim.trim(table.concat(lines, '\n')) .. '\n',
491481
})
@@ -503,6 +493,16 @@ return {
503493

504494
local lines = {}
505495

496+
if client.memory then
497+
table.insert(lines, '**Memory**')
498+
table.insert(lines, '```markdown')
499+
for _, line in ipairs(vim.split(client.memory.content, '\n')) do
500+
table.insert(lines, line)
501+
end
502+
table.insert(lines, '```')
503+
table.insert(lines, '')
504+
end
505+
506506
local selection = copilot.get_selection()
507507
if selection then
508508
table.insert(lines, '**Selection**')

0 commit comments

Comments
 (0)