From 1758b37d71b598b9a09227705125cc2dde3e22e9 Mon Sep 17 00:00:00 2001 From: Antoine Gaudreau Simard Date: Tue, 2 Sep 2025 14:06:02 -0400 Subject: [PATCH 1/2] refactor: check for nil timer --- lua/copilot-lsp/util.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/copilot-lsp/util.lua b/lua/copilot-lsp/util.lua index a4d28e0..247fe33 100644 --- a/lua/copilot-lsp/util.lua +++ b/lua/copilot-lsp/util.lua @@ -13,6 +13,8 @@ end ---@param delay integer function M.debounce(fn, delay) local timer = vim.uv.new_timer() + assert(timer) + return function(...) local argv = vim.F.pack_len(...) timer:start(delay, 0, function() From 7b510322380560e827cc5cc3ab8499cf0f4b8dc0 Mon Sep 17 00:00:00 2001 From: Antoine Gaudreau Simard Date: Tue, 2 Sep 2025 14:51:46 -0400 Subject: [PATCH 2/2] feat: groundwork for copilot.lua integration --- lsp/copilot_ls.lua | 25 +------------------------ lua/copilot-lsp/nes/init.lua | 27 +++++++++++++++++++++++++++ lua/copilot-lsp/util.lua | 6 ++++++ plugin/copilot-lsp.lua | 4 +--- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/lsp/copilot_ls.lua b/lsp/copilot_ls.lua index 95ac57b..973662f 100644 --- a/lsp/copilot_ls.lua +++ b/lsp/copilot_ls.lua @@ -41,29 +41,6 @@ return { -- inline_completion.request_inline_completion(1) -- end) - --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, - }) - - --NOTE: didFocus - vim.api.nvim_create_autocmd("BufEnter", { - callback = function() - local td_params = vim.lsp.util.make_text_document_params() - client:notify("textDocument/didFocus", { - textDocument = { - uri = td_params.uri, - }, - }) - end, - group = au, - }) + require("copilot-lsp.nes").lsp_on_init(client, au) end, } diff --git a/lua/copilot-lsp/nes/init.lua b/lua/copilot-lsp/nes/init.lua index 430466e..7c407f4 100644 --- a/lua/copilot-lsp/nes/init.lua +++ b/lua/copilot-lsp/nes/init.lua @@ -138,4 +138,31 @@ function M.clear() return false end +---@param client vim.lsp.Client +---@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, + }) + + --NOTE: didFocus + vim.api.nvim_create_autocmd("BufEnter", { + callback = function() + local td_params = vim.lsp.util.make_text_document_params() + client:notify("textDocument/didFocus", { + textDocument = { + uri = td_params.uri, + }, + }) + end, + group = au, + }) +end + return M diff --git a/lua/copilot-lsp/util.lua b/lua/copilot-lsp/util.lua index 247fe33..b93bd12 100644 --- a/lua/copilot-lsp/util.lua +++ b/lua/copilot-lsp/util.lua @@ -205,4 +205,10 @@ function M.hl_text_to_virt_lines(text, lang) return virt_lines end +function M.set_hl() + vim.api.nvim_set_hl(0, "CopilotLspNesAdd", { link = "DiffAdd", default = true }) + vim.api.nvim_set_hl(0, "CopilotLspNesDelete", { link = "DiffDelete", default = true }) + vim.api.nvim_set_hl(0, "CopilotLspNesApply", { link = "DiffText", default = true }) +end + return M diff --git a/plugin/copilot-lsp.lua b/plugin/copilot-lsp.lua index 15cd59a..1c8a2bb 100644 --- a/plugin/copilot-lsp.lua +++ b/plugin/copilot-lsp.lua @@ -1,3 +1 @@ -vim.api.nvim_set_hl(0, "CopilotLspNesAdd", { link = "DiffAdd", default = true }) -vim.api.nvim_set_hl(0, "CopilotLspNesDelete", { link = "DiffDelete", default = true }) -vim.api.nvim_set_hl(0, "CopilotLspNesApply", { link = "DiffText", default = true }) +require("copilot-lsp.util").set_hl()