Skip to content

Commit 64234a7

Browse files
committed
fix
1 parent 68df1c2 commit 64234a7

File tree

3 files changed

+38
-33
lines changed

3 files changed

+38
-33
lines changed

lua/copilot/copilot_handler.lua

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local user_data = require('copilot.setup').get_cred()
22
local util = require('copilot.util')
3+
local M = {}
34

45
local send_editor_info = function (a, b, c, d)
56
local responses = vim.lsp.buf_request_sync(0, 'setEditorInfo', {
@@ -17,33 +18,37 @@ end
1718
local capabilities = vim.lsp.protocol.make_client_capabilities()
1819
capabilities.getCompletions = true
1920

20-
vim.lsp.start_client({
21-
cmd = {require('copilot.util').get_copilot_path()},
22-
cmd_env = {
23-
["GITHUB_USER"] = user_data.user,
24-
["GITHUB_TOKEN"] = user_data.token,
25-
["COPILOT_AGENT_VERBOSE"] = 1,
26-
},
27-
handlers={
28-
["getCompletions"] = function () print("get completions") end,
29-
["textDocumentSync"] = function () print("handle") end,
30-
},
31-
name = "copilot",
32-
trace = "messages",
33-
root_dir = vim.loop.cwd(),
34-
autostart = true,
35-
on_init = function(client, _)
36-
vim.lsp.buf_attach_client(0, client.id)
37-
vim.api.nvim_create_autocmd({'BufEnter'}, {
38-
callback = function ()
39-
if not vim.lsp.buf_get_clients(0)[client.id] then
40-
vim.lsp.buf_attach_client(0, client.id)
41-
end
42-
end,
43-
once = false,
44-
})
45-
end,
46-
on_attach = function()
47-
send_editor_info()
48-
end
49-
})
21+
M.start = function (plugin_path)
22+
vim.lsp.start_client({
23+
cmd = {require('copilot.util').get_copilot_path(plugin_path)},
24+
cmd_env = {
25+
["GITHUB_USER"] = user_data.user,
26+
["GITHUB_TOKEN"] = user_data.token,
27+
["COPILOT_AGENT_VERBOSE"] = 1,
28+
},
29+
handlers={
30+
["getCompletions"] = function () print("get completions") end,
31+
["textDocumentSync"] = function () print("handle") end,
32+
},
33+
name = "copilot",
34+
trace = "messages",
35+
root_dir = vim.loop.cwd(),
36+
autostart = true,
37+
on_init = function(client, _)
38+
vim.lsp.buf_attach_client(0, client.id)
39+
vim.api.nvim_create_autocmd({'BufEnter'}, {
40+
callback = function ()
41+
if not vim.lsp.buf_get_clients(0)[client.id] then
42+
vim.lsp.buf_attach_client(0, client.id)
43+
end
44+
end,
45+
once = false,
46+
})
47+
end,
48+
on_attach = function()
49+
send_editor_info()
50+
end
51+
})
52+
end
53+
54+
return M

lua/copilot/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
require("copilot.copilot_handler")
1+
require("copilot.copilot_handler").start()

lua/copilot/util.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ M.get_completion_params = function()
2727
return params
2828
end
2929

30-
M.get_copilot_path = function()
31-
local root_path = vim.fn.stdpath("data") .. "/site/pack/packer/"
30+
M.get_copilot_path = function(plugin_path)
31+
local root_path = plugin_path or vim.fn.stdpath("data") .. "/site/pack/packer/"
3232
for _, loc in ipairs{"opt", "start"} do
3333
local copilot_path = root_path .. loc .. "/copilot.lua/copilot/index.js"
3434
if vim.fn.filereadable(copilot_path) ~= 0 then

0 commit comments

Comments
 (0)