Skip to content

Commit b03617a

Browse files
committed
feat(suggestion): reuse ctx when possible
1 parent 3c6a1d2 commit b03617a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

lua/copilot/suggestion.lua

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

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

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-
)
251+
displayLines[1] =
252+
string.sub(string.sub(suggestion.text, 1, (string.find(suggestion.text, "\n", 1, true) or 0) - 1), cursor_col)
255253

256254
local extmark = {
257255
id = copilot.extmark_id,
@@ -402,13 +400,13 @@ local function advance(count, ctx)
402400
update_preview(ctx)
403401
end
404402

405-
local function schedule()
403+
local function schedule(ctx)
406404
if not is_enabled() then
407405
clear()
408406
return
409407
end
410408

411-
update_preview()
409+
update_preview(ctx)
412410
local bufnr = vim.api.nvim_get_current_buf()
413411
copilot._copilot_timer = vim.fn.timer_start(copilot.debounce, function(timer)
414412
trigger(bufnr, timer)
@@ -420,7 +418,7 @@ function mod.next()
420418

421419
-- no suggestion request yet
422420
if not ctx.first then
423-
schedule()
421+
schedule(ctx)
424422
return
425423
end
426424

@@ -434,7 +432,7 @@ function mod.prev()
434432

435433
-- no suggestion request yet
436434
if not ctx.first then
437-
schedule()
435+
schedule(ctx)
438436
return
439437
end
440438

@@ -572,7 +570,7 @@ end
572570
local function on_cursor_moved_i()
573571
local ctx = get_ctx()
574572
if copilot._copilot_timer or ctx.params or should_auto_trigger() then
575-
schedule()
573+
schedule(ctx)
576574
end
577575
end
578576

0 commit comments

Comments
 (0)