Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ require("copilot.suggestion").accept_word()
require("copilot.suggestion").accept_line()
require("copilot.suggestion").next()
require("copilot.suggestion").prev()
require("copilot.suggestion").clear_preview()
require("copilot.suggestion").update_preview()
require("copilot.suggestion").dismiss()
require("copilot.suggestion").toggle_auto_trigger()
```
Expand Down
2 changes: 2 additions & 0 deletions doc/copilot.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ The `copilot.suggestion` module exposes the following functions:
require("copilot.suggestion").accept_line()
require("copilot.suggestion").next()
require("copilot.suggestion").prev()
require("copilot.suggestion").clear_preview()
require("copilot.suggestion").update_preview()
require("copilot.suggestion").dismiss()
require("copilot.suggestion").toggle_auto_trigger()
<
Expand Down
22 changes: 11 additions & 11 deletions lua/copilot/suggestion/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ local function cancel_inflight_requests(ctx)
end)
end

local function clear_preview()
function M.clear_preview()
logger.trace("suggestion clear preview")
vim.api.nvim_buf_del_extmark(0, copilot.ns_id, copilot.extmark_id)
end
Expand Down Expand Up @@ -251,14 +251,14 @@ local function get_current_suggestion(ctx)
end

---@param ctx? copilot_suggestion_context
local function update_preview(ctx)
function M.update_preview(ctx)
ctx = ctx or get_ctx()
logger.trace("suggestion update preview", ctx)

local suggestion = get_current_suggestion(ctx)
local displayLines = suggestion and vim.split(suggestion.displayText, "\n", { plain = true }) or {}

clear_preview()
M.clear_preview()

if not suggestion or #displayLines == 0 then
return
Expand Down Expand Up @@ -336,7 +336,7 @@ local function clear(ctx)
ctx = ctx or get_ctx()
stop_timer()
cancel_inflight_requests(ctx)
update_preview(ctx)
M.update_preview(ctx)
reset_ctx(ctx)
end

Expand Down Expand Up @@ -367,7 +367,7 @@ local function handle_trigger_request(err, data)
ctx.suggestions = data and data.completions or {}
ctx.choice = 1
ctx.shown_choices = {}
update_preview()
M.update_preview()
end

local function trigger(bufnr, timer)
Expand Down Expand Up @@ -438,7 +438,7 @@ local function get_suggestions_cycling(callback, ctx)
get_suggestions_cycling_callback(ctx, err, data)
end)
ctx.cycling = id --[[@as integer]]
update_preview(ctx)
M.update_preview(ctx)
end)
end
end
Expand All @@ -464,7 +464,7 @@ local function schedule(bufnr)
stop_timer()
end

update_preview()
M.update_preview()
bufnr = bufnr or vim.api.nvim_get_current_buf()
copilot._copilot_timer = vim.fn.timer_start(copilot.debounce, function(timer)
logger.trace("suggestion schedule timer", bufnr)
Expand Down Expand Up @@ -509,7 +509,7 @@ local function advance(count, ctx)
ctx.choice = #ctx.suggestions
end

update_preview(ctx)
M.update_preview(ctx)
end

---@param ctx copilot_suggestion_context
Expand Down Expand Up @@ -603,7 +603,7 @@ function M.accept(modifier)
ctx.accepted_partial = true
ignore_next_cursor_moved = true
else
clear_preview()
M.clear_preview()
newText = suggestion.text
end

Expand Down Expand Up @@ -656,7 +656,7 @@ function M.accept(modifier)
end

update_ctx_suggestion_position(ctx.choice, new_cursor_line - 1, last_col, bufnr)
update_preview(ctx)
M.update_preview(ctx)
end
end)()
end
Expand Down Expand Up @@ -702,7 +702,7 @@ function M.dismiss()
local ctx = get_ctx()
reject()
clear(ctx)
update_preview(ctx)
M.update_preview(ctx)
end

function M.is_visible()
Expand Down
12 changes: 11 additions & 1 deletion plugin/copilot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ local completion_store = {
[""] = { "auth", "attach", "detach", "disable", "enable", "panel", "status", "suggestion", "toggle", "version" },
auth = { "signin", "signout", "info" },
panel = { "accept", "jump_next", "jump_prev", "open", "refresh", "toggle", "close", "is_open" },
suggestion = { "accept", "accept_line", "accept_word", "dismiss", "next", "prev", "toggle_auto_trigger" },
suggestion = {
"accept",
"accept_line",
"accept_word",
"dismiss",
"next",
"prev",
"toggle_auto_trigger",
"clear_preview",
"update_preview",
},
workspace = { "add" },
}

Expand Down