|
1 | 1 | local user_data = require('copilot.setup').get_cred() |
2 | 2 | local util = require('copilot.util') |
| 3 | +local M = {} |
3 | 4 |
|
4 | 5 | local send_editor_info = function (a, b, c, d) |
5 | 6 | local responses = vim.lsp.buf_request_sync(0, 'setEditorInfo', { |
|
17 | 18 | local capabilities = vim.lsp.protocol.make_client_capabilities() |
18 | 19 | capabilities.getCompletions = true |
19 | 20 |
|
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 |
0 commit comments