Skip to content

Commit 3dac4f7

Browse files
authored
refactor(chat): error handle yanking code block (#2568)
Co-authored-by: Oli Morris <[email protected]>
1 parent 0c8d8e1 commit 3dac4f7

File tree

1 file changed

+8
-2
lines changed
  • lua/codecompanion/interactions/chat/keymaps

1 file changed

+8
-2
lines changed

lua/codecompanion/interactions/chat/keymaps/init.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,14 @@ local function yank_node(node)
342342
local cursor_position = vim.fn.getcurpos()
343343

344344
-- Create marks for the node range
345-
vim.api.nvim_buf_set_mark(0, "[", start_row + 1, start_col, {})
346-
vim.api.nvim_buf_set_mark(0, "]", end_row + 1, end_col - 1, {})
345+
local ok, _ = pcall(function()
346+
vim.api.nvim_buf_set_mark(0, "[", start_row + 1, start_col, {})
347+
vim.api.nvim_buf_set_mark(0, "]", end_row + 1, end_col - 1, {})
348+
end)
349+
350+
if not ok then
351+
return utils.notify("Failed to copy code block", vim.log.levels.WARN)
352+
end
347353

348354
-- Yank using marks
349355
vim.cmd(string.format('normal! `["%sy`]', config.interactions.chat.opts.register))

0 commit comments

Comments
 (0)