Skip to content

Commit 7b51032

Browse files
committed
feat: groundwork for copilot.lua integration
1 parent 1758b37 commit 7b51032

File tree

4 files changed

+35
-27
lines changed

4 files changed

+35
-27
lines changed

lsp/copilot_ls.lua

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,6 @@ return {
4141
-- inline_completion.request_inline_completion(1)
4242
-- end)
4343

44-
--NOTE: NES Completions
45-
local debounced_request = require("copilot-lsp.util").debounce(
46-
require("copilot-lsp.nes").request_nes,
47-
vim.g.copilot_nes_debounce or 500
48-
)
49-
vim.api.nvim_create_autocmd({ "TextChangedI", "TextChanged" }, {
50-
callback = function()
51-
debounced_request(client)
52-
end,
53-
group = au,
54-
})
55-
56-
--NOTE: didFocus
57-
vim.api.nvim_create_autocmd("BufEnter", {
58-
callback = function()
59-
local td_params = vim.lsp.util.make_text_document_params()
60-
client:notify("textDocument/didFocus", {
61-
textDocument = {
62-
uri = td_params.uri,
63-
},
64-
})
65-
end,
66-
group = au,
67-
})
44+
require("copilot-lsp.nes").lsp_on_init(client, au)
6845
end,
6946
}

lua/copilot-lsp/nes/init.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,31 @@ function M.clear()
138138
return false
139139
end
140140

141+
---@param client vim.lsp.Client
142+
---@param au integer
143+
function M.lsp_on_init(client, au)
144+
--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+
})
153+
154+
--NOTE: didFocus
155+
vim.api.nvim_create_autocmd("BufEnter", {
156+
callback = function()
157+
local td_params = vim.lsp.util.make_text_document_params()
158+
client:notify("textDocument/didFocus", {
159+
textDocument = {
160+
uri = td_params.uri,
161+
},
162+
})
163+
end,
164+
group = au,
165+
})
166+
end
167+
141168
return M

lua/copilot-lsp/util.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,10 @@ function M.hl_text_to_virt_lines(text, lang)
205205
return virt_lines
206206
end
207207

208+
function M.set_hl()
209+
vim.api.nvim_set_hl(0, "CopilotLspNesAdd", { link = "DiffAdd", default = true })
210+
vim.api.nvim_set_hl(0, "CopilotLspNesDelete", { link = "DiffDelete", default = true })
211+
vim.api.nvim_set_hl(0, "CopilotLspNesApply", { link = "DiffText", default = true })
212+
end
213+
208214
return M

plugin/copilot-lsp.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
vim.api.nvim_set_hl(0, "CopilotLspNesAdd", { link = "DiffAdd", default = true })
2-
vim.api.nvim_set_hl(0, "CopilotLspNesDelete", { link = "DiffDelete", default = true })
3-
vim.api.nvim_set_hl(0, "CopilotLspNesApply", { link = "DiffText", default = true })
1+
require("copilot-lsp.util").set_hl()

0 commit comments

Comments
 (0)