diff --git a/README.md b/README.md index d3d24a0..6bc1fde 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ You don’t need to configure anything, but you can customize the defaults: require('copilot-lsp').setup({ nes = { move_count_threshold = 3, -- Clear after 3 cursor movements + auto_trigger = true, -- Automatically trigger suggestions, if false then "nes_apply_pending_nes()" will request a new suggestion if none are visible } }) ``` diff --git a/lua/copilot-lsp/config.lua b/lua/copilot-lsp/config.lua index b4320a1..ffc60e3 100644 --- a/lua/copilot-lsp/config.lua +++ b/lua/copilot-lsp/config.lua @@ -4,6 +4,7 @@ ---@field clear_on_large_distance boolean Whether to clear suggestion when cursor is far away ---@field count_horizontal_moves boolean Whether to count horizontal cursor movements ---@field reset_on_approaching boolean Whether to reset counter when approaching suggestion +---@field auto_trigger boolean Whether to automatically trigger suggestion; if false then walk/accept will request one local M = {} @@ -16,6 +17,7 @@ M.defaults = { clear_on_large_distance = true, count_horizontal_moves = true, reset_on_approaching = true, + auto_trigger = true, }, } diff --git a/lua/copilot-lsp/nes/init.lua b/lua/copilot-lsp/nes/init.lua index 7c407f4..0b5e6c0 100644 --- a/lua/copilot-lsp/nes/init.lua +++ b/lua/copilot-lsp/nes/init.lua @@ -1,6 +1,7 @@ local errs = require("copilot-lsp.errors") local nes_ui = require("copilot-lsp.nes.ui") local utils = require("copilot-lsp.util") +local config = require("copilot-lsp.config").config local M = {} @@ -102,6 +103,7 @@ end --- This function applies the pending nes edit to the current buffer and then clears the marks for the pending --- suggestion +--- If there is no edit and auto_trigger is false, then a new suggestion will be requested ---@param bufnr? integer ---@return boolean --if the nes was applied function M.apply_pending_nes(bufnr) @@ -110,7 +112,11 @@ function M.apply_pending_nes(bufnr) ---@type copilotlsp.InlineEdit local state = vim.b[bufnr].nes_state if not state then - return false + if not config.auto_trigger then + M.request_nes() + else + return false + end end vim.schedule(function() utils.apply_inline_edit(state) @@ -142,14 +148,18 @@ end ---@param au integer function M.lsp_on_init(client, au) --NOTE: NES Completions - local debounced_request = - require("copilot-lsp.util").debounce(require("copilot-lsp.nes").request_nes, vim.g.copilot_nes_debounce or 500) - vim.api.nvim_create_autocmd({ "TextChangedI", "TextChanged" }, { - callback = function() - debounced_request(client) - end, - group = au, - }) + if config.nes.auto_trigger then + local debounced_request = require("copilot-lsp.util").debounce( + require("copilot-lsp.nes").request_nes, + vim.g.copilot_nes_debounce or 500 + ) + vim.api.nvim_create_autocmd({ "TextChangedI", "TextChanged" }, { + callback = function() + debounced_request(client) + end, + group = au, + }) + end --NOTE: didFocus vim.api.nvim_create_autocmd("BufEnter", {