diff --git a/README.md b/README.md index 956c78a4..7b6f5c48 100644 --- a/README.md +++ b/README.md @@ -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() ``` diff --git a/doc/copilot.txt b/doc/copilot.txt index 6f4adae2..9d949a94 100644 --- a/doc/copilot.txt +++ b/doc/copilot.txt @@ -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() < diff --git a/lua/copilot/suggestion/init.lua b/lua/copilot/suggestion/init.lua index 8b0e41b8..c03ee14c 100644 --- a/lua/copilot/suggestion/init.lua +++ b/lua/copilot/suggestion/init.lua @@ -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 @@ -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 @@ -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 @@ -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) @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 @@ -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() diff --git a/plugin/copilot.lua b/plugin/copilot.lua index b03a019f..1a042ea4 100644 --- a/plugin/copilot.lua +++ b/plugin/copilot.lua @@ -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" }, }