Skip to content

Commit e91b360

Browse files
committed
feat: add option to disable auto_trigger of nes
fixes #54
1 parent 7b51032 commit e91b360

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ You don’t need to configure anything, but you can customize the defaults:
7272
require('copilot-lsp').setup({
7373
nes = {
7474
move_count_threshold = 3, -- Clear after 3 cursor movements
75+
auto_trigger = true, -- Automatically trigger suggestions, if false then "nes_apply_pending_nes()" will request a new suggestion if none are visible
7576
}
7677
})
7778
```

lua/copilot-lsp/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
---@field clear_on_large_distance boolean Whether to clear suggestion when cursor is far away
55
---@field count_horizontal_moves boolean Whether to count horizontal cursor movements
66
---@field reset_on_approaching boolean Whether to reset counter when approaching suggestion
7+
---@field auto_trigger boolean Whether to automatically trigger suggestion; if false then walk/accept will request one
78

89
local M = {}
910

@@ -16,6 +17,7 @@ M.defaults = {
1617
clear_on_large_distance = true,
1718
count_horizontal_moves = true,
1819
reset_on_approaching = true,
20+
auto_trigger = true,
1921
},
2022
}
2123

lua/copilot-lsp/nes/init.lua

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local errs = require("copilot-lsp.errors")
22
local nes_ui = require("copilot-lsp.nes.ui")
33
local utils = require("copilot-lsp.util")
4+
local config = require("copilot-lsp.config").config
45

56
local M = {}
67

@@ -102,6 +103,7 @@ end
102103

103104
--- This function applies the pending nes edit to the current buffer and then clears the marks for the pending
104105
--- suggestion
106+
--- If there is no edit and auto_trigger is false, then a new suggestion will be requested
105107
---@param bufnr? integer
106108
---@return boolean --if the nes was applied
107109
function M.apply_pending_nes(bufnr)
@@ -110,7 +112,11 @@ function M.apply_pending_nes(bufnr)
110112
---@type copilotlsp.InlineEdit
111113
local state = vim.b[bufnr].nes_state
112114
if not state then
113-
return false
115+
if not config.auto_trigger then
116+
M.request_nes()
117+
else
118+
return false
119+
end
114120
end
115121
vim.schedule(function()
116122
utils.apply_inline_edit(state)
@@ -142,14 +148,18 @@ end
142148
---@param au integer
143149
function M.lsp_on_init(client, au)
144150
--NOTE: NES Completions
145-
local debounced_request =
146-
require("copilot-lsp.util").debounce(require("copilot-lsp.nes").request_nes, vim.g.copilot_nes_debounce or 500)
147-
vim.api.nvim_create_autocmd({ "TextChangedI", "TextChanged" }, {
148-
callback = function()
149-
debounced_request(client)
150-
end,
151-
group = au,
152-
})
151+
if config.nes.auto_trigger then
152+
local debounced_request = require("copilot-lsp.util").debounce(
153+
require("copilot-lsp.nes").request_nes,
154+
vim.g.copilot_nes_debounce or 500
155+
)
156+
vim.api.nvim_create_autocmd({ "TextChangedI", "TextChanged" }, {
157+
callback = function()
158+
debounced_request(client)
159+
end,
160+
group = au,
161+
})
162+
end
153163

154164
--NOTE: didFocus
155165
vim.api.nvim_create_autocmd("BufEnter", {

0 commit comments

Comments
 (0)