Skip to content

Commit 9481fc7

Browse files
committed
feat: add undocumented callback, currently used for testing
1 parent 87f298a commit 9481fc7

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lua/copilot/config/suggestion.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
---@alias SuggestionNotification fun(virtual_text: {}, virtual_lines: {})
2+
13
---@class (exact) SuggestionConfig
24
---@field enabled boolean Whether to enable the suggestion
35
---@field auto_trigger boolean Whether to trigger the suggestion automatically
46
---@field hide_during_completion boolean Whether to hide the suggestion during completion
57
---@field debounce integer Debounce time in milliseconds
68
---@field trigger_on_accept boolean To either trigger the suggestion on accept or pass the keystroke to the buffer
9+
---@field suggestion_notification SuggestionNotification|nil Callback function whenever a suggestion is triggered
710
---@field keymap SuggestionKeymapConfig Keymap for the suggestion
811

912
---@class (exact) SuggestionKeymapConfig
@@ -22,6 +25,7 @@ local suggestion = {
2225
hide_during_completion = true,
2326
debounce = 15,
2427
trigger_on_accept = true,
28+
suggestion_notification = nil,
2529
keymap = {
2630
accept = "<M-l>",
2731
accept_word = false,
@@ -39,6 +43,7 @@ function suggestion.validate(config)
3943
vim.validate("hide_during_completion", config.hide_during_completion, "boolean")
4044
vim.validate("debounce", config.debounce, { "number", "nil" })
4145
vim.validate("trigger_on_accept", config.trigger_on_accept, "boolean")
46+
vim.validate("suggestion_notification", config.suggestion_notification, { "function", "nil" })
4247
vim.validate("keymap", config.keymap, "table")
4348
vim.validate("keymap.accept", config.keymap.accept, { "string", "boolean" })
4449
vim.validate("keymap.accept_word", config.keymap.accept_word, { "string", "boolean" })

lua/copilot/suggestion/init.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,12 @@ local function update_preview(ctx)
292292

293293
vim.api.nvim_buf_set_extmark(0, copilot.ns_id, vim.fn.line(".") - 1, cursor_col - 1, extmark)
294294

295+
if config.suggestion.suggestion_notification then
296+
vim.schedule(function()
297+
config.suggestion.suggestion_notification(extmark.virt_text, extmark.virt_lines or {})
298+
end)
299+
end
300+
295301
if not ctx.shown_choices[suggestion.uuid] then
296302
ctx.shown_choices[suggestion.uuid] = true
297303
with_client(function(client)

0 commit comments

Comments
 (0)