From 3d7e7974d21f83f36964e56edb25b6d4bfe2e59a Mon Sep 17 00:00:00 2001 From: rockofox Date: Wed, 9 Nov 2022 16:26:14 +0100 Subject: [PATCH 1/2] feat: more sophisticated method to get copilot path --- README.md | 13 ------------- lua/copilot/client.lua | 2 +- lua/copilot/init.lua | 1 - lua/copilot/util.lua | 12 ++++++------ 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 5a214fda..1e991425 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,6 @@ require('copilot').setup({ ["."] = false, }, copilot_node_command = 'node', -- Node version must be < 18 - plugin_manager_path = vim.fn.stdpath("data") .. "/site/pack/packer", server_opts_overrides = {}, }) ``` @@ -201,18 +200,6 @@ Example: copilot_node_command = vim.fn.expand("$HOME") .. "/.config/nvm/versions/node/v16.14.2/bin/node", -- Node version must be < 18 ``` -### plugin_manager_path - -This is installation path of Packer, change this to the plugin manager installation path of your choice. - -Example: - -```lua -require("copilot").setup { - plugin_manager_path = vim.fn.stdpath("data") .. "/site/pack/packer", -} -``` - ### server_opts_overrides Override copilot lsp client settings. The `settings` field is where you can set the values of the options defined in [SettingsOpts.md](./SettingsOpts.md). diff --git a/lua/copilot/client.lua b/lua/copilot/client.lua index f01bcf04..3fe2231d 100644 --- a/lua/copilot/client.lua +++ b/lua/copilot/client.lua @@ -39,7 +39,7 @@ M.merge_server_opts = function (params) return vim.tbl_deep_extend("force", { cmd = { params.copilot_node_command or "node", - require("copilot.util").get_copilot_path(params.plugin_manager_path) + require("copilot.util").get_copilot_path(), }, cmd_cwd = vim.fn.expand('~'), root_dir = vim.loop.cwd(), diff --git a/lua/copilot/init.lua b/lua/copilot/init.lua index 2f146ff8..962c31ec 100644 --- a/lua/copilot/init.lua +++ b/lua/copilot/init.lua @@ -29,7 +29,6 @@ local defaults = { ft_disable = nil, filetypes = {}, copilot_node_command = "node", - plugin_manager_path = vim.fn.stdpath("data") .. "/site/pack/packer", server_opts_overrides = {}, } diff --git a/lua/copilot/util.lua b/lua/copilot/util.lua index 1402aa83..3d075649 100644 --- a/lua/copilot/util.lua +++ b/lua/copilot/util.lua @@ -229,12 +229,12 @@ function M.get_editor_configuration() } end -M.get_copilot_path = function(plugin_path) - for _, loc in ipairs({ "/opt", "/start", "" }) do - local copilot_path = plugin_path .. loc .. "/copilot.lua/copilot/index.js" - if vim.fn.filereadable(copilot_path) ~= 0 then - return copilot_path - end +M.get_copilot_path = function() + local copilot_path = string.gsub(debug.getinfo(1).source:sub(2), "lua/copilot/util.lua", "") .. "copilot/index.js" + if vim.fn.filereadable(copilot_path) ~= 0 then + return copilot_path + else + print("[Copilot] could not read" .. copilot_path) end end From 577c4312cbfdc17d0ced7591d903482b912043c1 Mon Sep 17 00:00:00 2001 From: rocko Date: Fri, 11 Nov 2022 08:50:22 +0100 Subject: [PATCH 2/2] fix: use `nvim_get_runtime_file` to find copilot --- lua/copilot/util.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/copilot/util.lua b/lua/copilot/util.lua index 61364b29..7b3e511e 100644 --- a/lua/copilot/util.lua +++ b/lua/copilot/util.lua @@ -230,7 +230,7 @@ function M.get_editor_configuration() end M.get_copilot_path = function() - local copilot_path = string.gsub(debug.getinfo(1).source:sub(2), "lua/copilot/util.lua", "") .. "copilot/index.js" + local copilot_path = vim.api.nvim_get_runtime_file('copilot/index.js', false)[1] if vim.fn.filereadable(copilot_path) ~= 0 then return copilot_path else