Skip to content

Commit 0e3585b

Browse files
committed
feat: add ability to set custom copilot binary
Fixes #407
1 parent 73dbc0e commit 0e3585b

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ require('copilot').setup({
129129

130130
return true
131131
end,
132+
lsp_binary = nil,
132133
server_opts_overrides = {},
133134
})
134135
```
@@ -343,6 +344,18 @@ require("copilot").setup {
343344
}
344345
```
345346

347+
### lsp_binary
348+
349+
This allows you to specify the path to the copilot lsp binary.
350+
This will disable the download of the binary and use the one specified.
351+
example:
352+
353+
```lua
354+
require("copilot").setup {
355+
lsp_binary = "/home/user/.local/bin/copilot-language-server",
356+
}
357+
```
358+
346359
## Commands
347360

348361
`copilot.lua` defines the `:Copilot` command that can perform various actions. It has completion support, so try it out.

lua/copilot/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ local default_config = {
7575

7676
return true
7777
end,
78+
---@type string|nil
79+
lsp_binary = nil,
7880
}
7981

8082
local mod = {

lua/copilot/init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local highlight = require("copilot.highlight")
44
local logger = require("copilot.logger")
55
local client = require("copilot.client")
66
local auth = require("copilot.auth")
7+
local lsp_binary = require("copilot.lsp_binary")
78

89
local create_cmds = function()
910
vim.api.nvim_create_user_command("CopilotDetach", function()
@@ -41,6 +42,7 @@ M.setup = function(opts)
4142
create_cmds()
4243
end
4344

45+
lsp_binary.setup(conf.lsp_binary)
4446
require("copilot.command").enable()
4547
logger.setup(conf.logger)
4648

lua/copilot/lsp_binary.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,27 @@ function M.get_copilot_server_info()
265265
return M.copilot_server_info
266266
end
267267

268+
function M.setup(filepath)
269+
if not filepath then
270+
return M
271+
end
272+
273+
if not vim.fn.filereadable(filepath) then
274+
logger.error("copilot-language-server not found at " .. filepath)
275+
return M
276+
end
277+
278+
M.copilot_server_info = {
279+
path = "",
280+
filename = "",
281+
absolute_path = "",
282+
absolute_filepath = vim.fs.normalize(filepath),
283+
extracted_filename = "",
284+
}
285+
286+
logger.debug("using custom copilot-language-server binary:", M.copilot_server_info.absolute_filepath)
287+
288+
M.initialized = true
289+
end
290+
268291
return M

0 commit comments

Comments
 (0)