Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
```
Expand Down
2 changes: 2 additions & 0 deletions lua/copilot-lsp/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand All @@ -16,6 +17,7 @@ M.defaults = {
clear_on_large_distance = true,
count_horizontal_moves = true,
reset_on_approaching = true,
auto_trigger = true,
},
}

Expand Down
28 changes: 19 additions & 9 deletions lua/copilot-lsp/nes/init.lua
Original file line number Diff line number Diff line change
@@ -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 = {}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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", {
Expand Down
Loading