Skip to content

Commit 74611b5

Browse files
authored
fix(chat): do not create multiple chat isntances (#1432)
this breaks notification listeners Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
1 parent 386b51b commit 74611b5

2 files changed

Lines changed: 30 additions & 30 deletions

File tree

lua/CopilotChat/init.lua

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,41 +1100,41 @@ function M.setup(config)
11001100
if M.chat then
11011101
M.chat:close(state.source.bufnr)
11021102
M.chat:delete()
1103-
end
1104-
1105-
M.chat = require('CopilotChat.ui.chat')(M.config, function(bufnr)
1106-
for name, _ in pairs(M.config.mappings) do
1107-
map_key(name, bufnr)
1108-
end
1109-
1110-
require('CopilotChat.completion').enable(bufnr, M.config.chat_autocomplete)
1103+
else
1104+
M.chat = require('CopilotChat.ui.chat')(M.config, function(bufnr)
1105+
for name, _ in pairs(M.config.mappings) do
1106+
map_key(name, bufnr)
1107+
end
11111108

1112-
vim.api.nvim_create_autocmd({ 'BufEnter', 'BufLeave' }, {
1113-
buffer = bufnr,
1114-
callback = function(ev)
1115-
if ev.event == 'BufEnter' then
1116-
update_source()
1117-
end
1109+
require('CopilotChat.completion').enable(bufnr, M.config.chat_autocomplete)
11181110

1119-
vim.schedule(function()
1120-
select.highlight(state.source.bufnr, not (M.config.highlight_selection and M.chat:focused()))
1121-
end)
1122-
end,
1123-
})
1124-
1125-
if M.config.insert_at_end then
1126-
vim.api.nvim_create_autocmd({ 'InsertEnter' }, {
1111+
vim.api.nvim_create_autocmd({ 'BufEnter', 'BufLeave' }, {
11271112
buffer = bufnr,
1128-
callback = function()
1129-
vim.cmd('normal! 0')
1130-
vim.cmd('normal! G$')
1131-
vim.v.char = 'x'
1113+
callback = function(ev)
1114+
if ev.event == 'BufEnter' then
1115+
update_source()
1116+
end
1117+
1118+
vim.schedule(function()
1119+
select.highlight(state.source.bufnr, not (M.config.highlight_selection and M.chat:focused()))
1120+
end)
11321121
end,
11331122
})
1134-
end
11351123

1136-
finish(true)
1137-
end)
1124+
if M.config.insert_at_end then
1125+
vim.api.nvim_create_autocmd({ 'InsertEnter' }, {
1126+
buffer = bufnr,
1127+
callback = function()
1128+
vim.cmd('normal! 0')
1129+
vim.cmd('normal! G$')
1130+
vim.v.char = 'x'
1131+
end,
1132+
})
1133+
end
1134+
1135+
finish(true)
1136+
end)
1137+
end
11381138

11391139
for name, prompt in pairs(list_prompts()) do
11401140
if prompt.prompt then

lua/CopilotChat/ui/chat.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ local Chat = class(function(self, config, on_buf_create)
164164
if not msg or msg == '' then
165165
self.chat_overlay:restore(self.winnr, self.bufnr)
166166
else
167-
self:overlay({ text = msg })
167+
self.chat_overlay:show(msg, self.winnr)
168168
end
169169
end)
170170
end, Overlay)

0 commit comments

Comments
 (0)