Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions lua/copilot/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"))
Expand Down
1 change: 0 additions & 1 deletion lua/copilot/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
37 changes: 18 additions & 19 deletions lua/copilot/lsp_binary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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