From 6a3134e95c2487bc6d3e4e63b5cb03da69051f3e Mon Sep 17 00:00:00 2001 From: Antoine Gaudreau Simard Date: Sat, 29 Mar 2025 12:06:12 -0400 Subject: [PATCH 1/2] fix: improvements to the binary downloading timing --- lua/copilot/client.lua | 12 ++++++++++++ lua/copilot/init.lua | 1 - lua/copilot/lsp_binary.lua | 37 ++++++++++++++++++------------------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/lua/copilot/client.lua b/lua/copilot/client.lua index 77793c4f..87e35ef8 100644 --- a/lua/copilot/client.lua +++ b/lua/copilot/client.lua @@ -230,6 +230,11 @@ local function prepare_client_config(overrides) } end + if not cmd then + logger.error("copilot server type not supported") + return + end + local capabilities = vim.lsp.protocol.make_client_capabilities() --[[@as copilot_capabilities]] capabilities.window.showDocument.support = true @@ -348,8 +353,15 @@ function M.setup() local server_config = config.get("server") --[[@as copilot_config_server]] local node_command = config.get("copilot_node_command") --[[@as string|nil]] M.server = vim.tbl_deep_extend("force", M.server, server_config) + + if M.server.custom_server_filepath then + M.server.custom_server_filepath = vim.fs.normalize(M.server.custom_server_filepath) + end + if M.server.type == "nodejs" then lsp_nodesj.setup(node_command, M.server.custom_server_filepath) + elseif M.server.type == "binary" then + lsp_binary.setup(M.server.custom_server_filepath) end M.config = prepare_client_config(config.get("server_opts_overrides")) diff --git a/lua/copilot/init.lua b/lua/copilot/init.lua index 35fd8ae4..4169cc7a 100644 --- a/lua/copilot/init.lua +++ b/lua/copilot/init.lua @@ -42,7 +42,6 @@ M.setup = function(opts) create_cmds() end - lsp_binary.setup(conf.lsp_binary) require("copilot.command").enable() logger.setup(conf.logger) diff --git a/lua/copilot/lsp_binary.lua b/lua/copilot/lsp_binary.lua index f3b272a1..de745d9b 100644 --- a/lua/copilot/lsp_binary.lua +++ b/lua/copilot/lsp_binary.lua @@ -326,28 +326,27 @@ function M.get_server_path() return M.get_copilot_server_info().absolute_filepath end ----@param filepath string|nil -function M.setup(filepath) - if not filepath then - return M - end +---@param custom_server_path? string +function M.setup(custom_server_path) + if custom_server_path then + if not vim.fn.filereadable(custom_server_path) then + logger.error("copilot-language-server not found at " .. custom_server_path) + return M + end - if not vim.fn.filereadable(filepath) then - logger.error("copilot-language-server not found at " .. filepath) - return M - end + logger.debug("using custom copilot-language-server binary:", custom_server_path) + M.copilot_server_info = { + path = "", + filename = "", + absolute_path = "", + absolute_filepath = custom_server_path or "", + extracted_filename = "", + } - M.copilot_server_info = { - path = "", - filename = "", - absolute_path = "", - absolute_filepath = vim.fs.normalize(filepath), - extracted_filename = "", - } - - logger.debug("using custom copilot-language-server binary:", M.copilot_server_info.absolute_filepath) + M.initialized = true + end - M.initialized = true + M.ensure_client_is_downloaded() end return M From 0d56d43d2d2c0c8cf897a338be402bd639a906ae Mon Sep 17 00:00:00 2001 From: omahs <73983677+omahs@users.noreply.github.com> Date: Fri, 28 Mar 2025 20:24:37 +0100 Subject: [PATCH 2/2] fix: typos --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dc6294a9..d62f1c48 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Note that if you have the variable set, even empty, the LSP will attempt to use You have to run the `require("copilot").setup(options)` function in order to start Copilot. If no options are provided, the defaults are used. -Because the copilot server takes some time to start up, it is recommend that you lazy load copilot. +Because the copilot server takes some time to start up, it is recommended that you lazy load copilot. For example: ```lua @@ -296,7 +296,7 @@ copilot_node_command = vim.fn.expand("$HOME") .. "/.config/nvm/versions/node/v20 ### 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). -These options are specific to the copilot lsp and can be used to customize its behavior. Ensure that the name field is not overriden as is is used for +These options are specific to the copilot lsp and can be used to customize its behavior. Ensure that the name field is not overridden as is is used for efficiency reasons in numerous checks to verify copilot is actually running. See `:h vim.lsp.start_client` for list of options. Example: @@ -340,7 +340,7 @@ If none is found, it will use the current working directory. This function is called to determine if copilot should attach to the buffer or not. It is useful if you would like to go beyond the filetypes and have more control over when copilot should attach. -You can also use it to attach to buflisted buffers by simply omiting that portion from the function. +You can also use it to attach to buflisted buffers by simply omitting that portion from the function. Since this happens before attaching to the buffer, it is good to prevent Copilot from reading sensitive files. An example of this would be: