Skip to content

Commit c093aa5

Browse files
committed
0.6 copilot not attaching
1 parent d03e265 commit c093aa5

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

lua/copilot/copilot_handler.lua

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ M.start = function(plugin_path)
3939
root_dir = vim.loop.cwd(),
4040
autostart = true,
4141
on_init = function(client, _)
42-
vim.lsp.buf_attach_client(0, client.id)
43-
vim.api.nvim_create_autocmd({ "BufEnter" }, {
44-
callback = function()
45-
if not vim.lsp.buf_get_clients(0)[client.id] then
46-
vim.lsp.buf_attach_client(0, client.id)
47-
end
48-
end,
49-
once = false,
50-
})
51-
end,
52-
on_attach = function()
5342
send_editor_info()
43+
vim.lsp.buf_attach_client(0, client.id)
44+
if vim.fn.has("nvim-0.7") then
45+
vim.api.nvim_create_autocmd({ "BufEnter" }, {
46+
callback = function()
47+
util.attach_copilot()
48+
end,
49+
once = false,
50+
})
51+
else
52+
vim.cmd("au BufEnter * lua require('copilot.util').attach_copilot()")
53+
end
5454
end,
5555
})
5656
end

lua/copilot/util.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local M = {}
22

3+
34
local format_pos = function()
45
local pos = vim.api.nvim_win_get_cursor(0)
56
return { character = pos[2], line = pos[1] - 1 }
@@ -10,6 +11,22 @@ local get_relfile = function()
1011
return file
1112
end
1213

14+
M.find_copilot_client = function ()
15+
for _, client in ipairs(vim.lsp.get_active_clients()) do
16+
if client.name == "copilot" then
17+
return client.id
18+
end
19+
end
20+
print("Copilot not started!")
21+
end
22+
23+
M.attach_copilot = function ()
24+
local client_id = require("copilot.util").find_copilot_client()
25+
if not vim.lsp.buf_get_clients(0)[client_id] then
26+
vim.lsp.buf_attach_client(0, client_id)
27+
end
28+
end
29+
1330
M.get_completion_params = function()
1431
local params = {
1532
options = vim.empty_dict(),

0 commit comments

Comments
 (0)