Skip to content

Commit d1f5d0b

Browse files
committed
feat(client): add compatibility for neovim < 0.8.2
1 parent 7ba514e commit d1f5d0b

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

lua/copilot/client.lua

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@ local function store_client_id(id)
1616
M.id = id
1717
end
1818

19+
local lsp_start = vim.lsp.start
20+
if not lsp_start then
21+
local function reuse_client(client, conf)
22+
return client.config.root_dir == conf.root_dir and client.name == conf.name
23+
end
24+
25+
-- shim for neovim < 0.8.2
26+
lsp_start = function(lsp_config)
27+
local bufnr = vim.api.nvim_get_current_buf()
28+
local client = M.get()
29+
if client and reuse_client(client, lsp_config) then
30+
vim.lsp.buf_attach_client(bufnr, client.id)
31+
return client.id
32+
end
33+
local client_id = vim.lsp.start_client(lsp_config) --[[@as number]]
34+
vim.lsp.buf_attach_client(bufnr, client_id)
35+
return client_id
36+
end
37+
end
38+
1939
local copilot_node_version = nil
2040
function M.get_node_version()
2141
if not copilot_node_version then
@@ -37,7 +57,7 @@ function M.buf_attach(force)
3757
return
3858
end
3959

40-
local client_id = vim.lsp.start(M.config)
60+
local client_id = lsp_start(M.config)
4161
store_client_id(client_id)
4262
end
4363

0 commit comments

Comments
 (0)