From d9ddd3e48611ae752ecfe66fe127cb8a2638f1f5 Mon Sep 17 00:00:00 2001 From: Champii Date: Tue, 5 Apr 2022 12:34:33 +0200 Subject: [PATCH 1/9] Use a config dict and allow override of copilot plugin path --- lua/copilot/copilot_handler.lua | 4 ++-- lua/copilot/util.lua | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/copilot/copilot_handler.lua b/lua/copilot/copilot_handler.lua index 193d23eb..0c7c0cc6 100644 --- a/lua/copilot/copilot_handler.lua +++ b/lua/copilot/copilot_handler.lua @@ -18,9 +18,9 @@ end local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities.getCompletions = true -M.start = function (plugin_path) +M.start = function (config) vim.lsp.start_client({ - cmd = {require('copilot.util').get_copilot_path(plugin_path)}, + cmd = {require('copilot.util').get_copilot_path(config)}, cmd_env = { ["GITHUB_USER"] = user_data.user, ["GITHUB_TOKEN"] = user_data.token, diff --git a/lua/copilot/util.lua b/lua/copilot/util.lua index 529f987a..4b078ebc 100644 --- a/lua/copilot/util.lua +++ b/lua/copilot/util.lua @@ -27,8 +27,12 @@ M.get_completion_params = function() return params end -M.get_copilot_path = function(plugin_path) - local root_path = plugin_path or vim.fn.stdpath("data") +M.get_copilot_path = function(config) + if config.copilot_path ~= nil then + return config.copilot_path + end + + local root_path = config.pack_path or vim.fn.stdpath("data") local packer_path = root_path .. "/site/pack/packer/" for _, loc in ipairs{"opt", "start"} do local copilot_path = packer_path .. loc .. "/copilot.lua/copilot/index.js" From 3fe7e812965097b487db3832b8cd0ef7d40f27df Mon Sep 17 00:00:00 2001 From: Champii Date: Tue, 5 Apr 2022 15:09:20 +0200 Subject: [PATCH 2/9] Test with buffer attach --- lua/copilot/copilot_handler.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lua/copilot/copilot_handler.lua b/lua/copilot/copilot_handler.lua index 0c7c0cc6..b2acb4db 100644 --- a/lua/copilot/copilot_handler.lua +++ b/lua/copilot/copilot_handler.lua @@ -9,7 +9,7 @@ local send_editor_info = function (a, b, c, d) version = '1.1.0', }, editorInfo= { - version = '0.7.0-dev+1343-g4d3acd6be-dirty', + version = '0.6.1', name = "Neovim", }, }, 600) @@ -36,14 +36,12 @@ M.start = function (config) autostart = true, on_init = function(client, _) vim.lsp.buf_attach_client(0, client.id) - vim.api.nvim_create_autocmd({'BufEnter'}, { + vim.api.nvim_command[[autocmd BufEnter * lua require('copilot.copilot_handler')._on_init(client)]] + --[[ vim.api.nvim_create_autocmd({'BufEnter'}, { callback = function () - if not vim.lsp.buf_get_clients(0)[client.id] then - vim.lsp.buf_attach_client(0, client.id) - end end, once = false, - }) + }) ]] end, on_attach = function() send_editor_info() @@ -51,4 +49,10 @@ M.start = function (config) }) end +M._on_init = function(client) + if not vim.lsp.buf_get_clients(0)[client.id] then + vim.lsp.buf_attach_client(0, client.id) + end +end + return M From eadcbf3e99ac0dfadbec6d92eb00b5972b7d8e32 Mon Sep 17 00:00:00 2001 From: Champii Date: Tue, 5 Apr 2022 15:16:43 +0200 Subject: [PATCH 3/9] Try again for autocommands --- lua/copilot/copilot_handler.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/copilot/copilot_handler.lua b/lua/copilot/copilot_handler.lua index b2acb4db..e8f8feb2 100644 --- a/lua/copilot/copilot_handler.lua +++ b/lua/copilot/copilot_handler.lua @@ -36,7 +36,7 @@ M.start = function (config) autostart = true, on_init = function(client, _) vim.lsp.buf_attach_client(0, client.id) - vim.api.nvim_command[[autocmd BufEnter * lua require('copilot.copilot_handler')._on_init(client)]] + vim.api.nvim_command([[autocmd BufEnter * lua require('copilot.copilot_handler')._on_init(]] + client.id + ")") --[[ vim.api.nvim_create_autocmd({'BufEnter'}, { callback = function () end, @@ -49,9 +49,9 @@ M.start = function (config) }) end -M._on_init = function(client) - if not vim.lsp.buf_get_clients(0)[client.id] then - vim.lsp.buf_attach_client(0, client.id) +M._on_init = function(client_id) + if not vim.lsp.buf_get_clients(0)[client_id] then + vim.lsp.buf_attach_client(0, client_id) end end From 14736649ddda26e1c7c6cdd97aa66e0ae1dec285 Mon Sep 17 00:00:00 2001 From: Champii Date: Tue, 5 Apr 2022 15:20:00 +0200 Subject: [PATCH 4/9] Add handler for rust --- lua/copilot/copilot_handler.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/copilot/copilot_handler.lua b/lua/copilot/copilot_handler.lua index e8f8feb2..239fd8ec 100644 --- a/lua/copilot/copilot_handler.lua +++ b/lua/copilot/copilot_handler.lua @@ -26,6 +26,7 @@ M.start = function (config) ["GITHUB_TOKEN"] = user_data.token, ["COPILOT_AGENT_VERBOSE"] = 1, }, + filetypes = { "rust" }, handlers={ ["getCompletions"] = function () print("get completions") end, ["textDocumentSync"] = function () print("handle") end, From 91fc818c5d033c71497061e35e41058ced6e2ab4 Mon Sep 17 00:00:00 2001 From: Champii Date: Tue, 5 Apr 2022 15:26:17 +0200 Subject: [PATCH 5/9] Test --- lua/copilot/copilot_handler.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/copilot/copilot_handler.lua b/lua/copilot/copilot_handler.lua index 239fd8ec..c468c96c 100644 --- a/lua/copilot/copilot_handler.lua +++ b/lua/copilot/copilot_handler.lua @@ -51,9 +51,9 @@ M.start = function (config) end M._on_init = function(client_id) - if not vim.lsp.buf_get_clients(0)[client_id] then - vim.lsp.buf_attach_client(0, client_id) - end + -- if not vim.lsp.buf_get_clients(0)[client_id] then + vim.lsp.buf_attach_client(0, client_id) + -- end end return M From d6036d2f878eb67d9af740a7071ee787d7223ef2 Mon Sep 17 00:00:00 2001 From: Champii Date: Tue, 5 Apr 2022 15:36:51 +0200 Subject: [PATCH 6/9] Maybe this time it will work --- lua/copilot/copilot_handler.lua | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lua/copilot/copilot_handler.lua b/lua/copilot/copilot_handler.lua index c468c96c..1105f571 100644 --- a/lua/copilot/copilot_handler.lua +++ b/lua/copilot/copilot_handler.lua @@ -37,12 +37,7 @@ M.start = function (config) autostart = true, on_init = function(client, _) vim.lsp.buf_attach_client(0, client.id) - vim.api.nvim_command([[autocmd BufEnter * lua require('copilot.copilot_handler')._on_init(]] + client.id + ")") - --[[ vim.api.nvim_create_autocmd({'BufEnter'}, { - callback = function () - end, - once = false, - }) ]] + vim.api.nvim_command([[autocmd BufEnter * lua require('copilot.copilot_handler')._on_init(]] .. client.id .. ")") end, on_attach = function() send_editor_info() @@ -51,9 +46,10 @@ M.start = function (config) end M._on_init = function(client_id) - -- if not vim.lsp.buf_get_clients(0)[client_id] then - vim.lsp.buf_attach_client(0, client_id) - -- end + print(client_id) + if not vim.lsp.buf_get_clients(0)[client_id] then + vim.lsp.buf_attach_client(0, client_id) + end end return M From 2d018fe291443fedcfeb6d0165087096fec5033e Mon Sep 17 00:00:00 2001 From: Champii Date: Wed, 6 Apr 2022 14:03:41 +0200 Subject: [PATCH 7/9] Removed debug print --- lua/copilot/copilot_handler.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/copilot/copilot_handler.lua b/lua/copilot/copilot_handler.lua index 1105f571..bf542bb9 100644 --- a/lua/copilot/copilot_handler.lua +++ b/lua/copilot/copilot_handler.lua @@ -46,7 +46,6 @@ M.start = function (config) end M._on_init = function(client_id) - print(client_id) if not vim.lsp.buf_get_clients(0)[client_id] then vim.lsp.buf_attach_client(0, client_id) end From ef10606b7556d8cf2cfcffbaa278f0f28ac1d19f Mon Sep 17 00:00:00 2001 From: Champii Date: Sun, 15 May 2022 01:22:59 +0200 Subject: [PATCH 8/9] Try all filetypes --- lua/copilot/copilot_handler.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/copilot/copilot_handler.lua b/lua/copilot/copilot_handler.lua index 60eb710e..74d19583 100644 --- a/lua/copilot/copilot_handler.lua +++ b/lua/copilot/copilot_handler.lua @@ -26,6 +26,7 @@ M.merge_server_opts = function (params) cmd = { "node", require("copilot.util").get_copilot_path(params.plugin_manager_path) }, name = "copilot", trace = "messages", + filetypes = { "*" }, root_dir = vim.loop.cwd(), autostart = true, on_init = function(_, _) From f7bcbc1b1ed87be27694a58e8db9a0a0f3eacd83 Mon Sep 17 00:00:00 2001 From: Champii Date: Sun, 15 May 2022 01:25:17 +0200 Subject: [PATCH 9/9] Roll back to rust only --- lua/copilot/copilot_handler.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/copilot/copilot_handler.lua b/lua/copilot/copilot_handler.lua index 74d19583..fc09553b 100644 --- a/lua/copilot/copilot_handler.lua +++ b/lua/copilot/copilot_handler.lua @@ -26,7 +26,7 @@ M.merge_server_opts = function (params) cmd = { "node", require("copilot.util").get_copilot_path(params.plugin_manager_path) }, name = "copilot", trace = "messages", - filetypes = { "*" }, + filetypes = { "rust" }, root_dir = vim.loop.cwd(), autostart = true, on_init = function(_, _)