Skip to content

Commit 38a41d0

Browse files
committed
fix(suggestion): notify error about failed notify_accepted
1 parent 3665ed0 commit 38a41d0

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

lua/copilot/suggestion.lua

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,10 @@ local function update_preview(ctx)
248248

249249
local cursor_col = vim.fn.col(".")
250250

251-
displayLines[1] =
252-
string.sub(string.sub(suggestion.text, 1, (string.find(suggestion.text, "\n", 1, true) or 0) - 1), cursor_col)
251+
displayLines[1] = string.sub(
252+
string.sub(suggestion.text, 1, (string.find(suggestion.text, "\n", 1, true) or 0) - 1),
253+
cursor_col
254+
)
253255

254256
local extmark = {
255257
id = copilot.extmark_id,
@@ -458,11 +460,19 @@ function mod.accept(modifier)
458460
end
459461

460462
with_client(function(client)
461-
api.notify_accepted(
462-
client,
463-
{ uuid = suggestion.uuid, acceptedLength = util.strutf16len(suggestion.text) },
464-
function() end
465-
)
463+
local ok, err = pcall(function()
464+
api.notify_accepted(
465+
client,
466+
{ uuid = suggestion.uuid, acceptedLength = util.strutf16len(suggestion.text) },
467+
function() end
468+
)
469+
end)
470+
if not ok then
471+
vim.notify(
472+
table.concat({ "[Copilot] failed to notify_accepted for: " .. suggestion.text, "Error: " .. err }, "\n\n"),
473+
vim.log.levels.ERROR
474+
)
475+
end
466476
end)
467477

468478
clear_preview()

0 commit comments

Comments
 (0)