Skip to content

Commit e675c31

Browse files
committed
fix: removed deprecated function.
1 parent a9228e0 commit e675c31

1 file changed

Lines changed: 71 additions & 71 deletions

File tree

lua/_copilot.lua

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,89 @@
11
local copilot = {}
22

33
local showDocument = function(err, result, ctx, _)
4-
local fallback = vim.lsp.handlers['window/showDocument']
5-
if not fallback or (result.external and vim.g.copilot_browser) then
6-
return vim.fn['copilot#handlers#window_showDocument'](result)
7-
else
8-
return fallback(err, result, ctx, _)
9-
end
4+
local fallback = vim.lsp.handlers["window/showDocument"]
5+
if not fallback or (result.external and vim.g.copilot_browser) then
6+
return vim.fn["copilot#handlers#window_showDocument"](result)
7+
else
8+
return fallback(err, result, ctx, _)
9+
end
1010
end
1111

1212
copilot.lsp_start_client = function(cmd, handler_names, opts, settings)
13-
local handlers = {['window/showDocument'] = showDocument}
14-
local id
15-
for _, name in ipairs(handler_names) do
16-
handlers[name] = function(err, result, ctx, _)
17-
if result then
18-
local retval = vim.call('copilot#client#LspHandle', id, { method = name, params = result })
19-
if type(retval) == 'table' then
20-
return retval.result, retval.error
21-
elseif vim.lsp.handlers[name] then
22-
return vim.lsp.handlers[name](err, result, ctx, _)
23-
end
24-
end
25-
end
26-
end
27-
local workspace_folders = opts.workspaceFolders
28-
if #workspace_folders == 0 then
29-
workspace_folders = nil
30-
end
31-
id = vim.lsp.start_client({
32-
cmd = cmd,
33-
cmd_cwd = vim.call('copilot#job#Cwd'),
34-
name = 'GitHub Copilot',
35-
init_options = opts.initializationOptions,
36-
workspace_folders = workspace_folders,
37-
settings = settings,
38-
handlers = handlers,
39-
on_init = function(client, initialize_result)
40-
vim.call('copilot#client#LspInit', client.id, initialize_result)
41-
if vim.fn.has('nvim-0.8') == 0 then
42-
client.notify('workspace/didChangeConfiguration', { settings = settings })
43-
end
44-
end,
45-
on_exit = function(code, signal, client_id)
46-
vim.schedule(function()
47-
vim.call('copilot#client#LspExit', client_id, code, signal)
48-
end)
49-
end,
50-
})
51-
return id
13+
local handlers = { ["window/showDocument"] = showDocument }
14+
local id
15+
for _, name in ipairs(handler_names) do
16+
handlers[name] = function(err, result, ctx, _)
17+
if result then
18+
local retval = vim.call("copilot#client#LspHandle", id, { method = name, params = result })
19+
if type(retval) == "table" then
20+
return retval.result, retval.error
21+
elseif vim.lsp.handlers[name] then
22+
return vim.lsp.handlers[name](err, result, ctx, _)
23+
end
24+
end
25+
end
26+
end
27+
local workspace_folders = opts.workspaceFolders
28+
if #workspace_folders == 0 then
29+
workspace_folders = nil
30+
end
31+
id = vim.lsp.start({
32+
cmd = cmd,
33+
cmd_cwd = vim.call("copilot#job#Cwd"),
34+
name = "GitHub Copilot",
35+
init_options = opts.initializationOptions,
36+
workspace_folders = workspace_folders,
37+
settings = settings,
38+
handlers = handlers,
39+
on_init = function(client, initialize_result)
40+
vim.call("copilot#client#LspInit", client.id, initialize_result)
41+
if vim.fn.has("nvim-0.8") == 0 then
42+
client.notify("workspace/didChangeConfiguration", { settings = settings })
43+
end
44+
end,
45+
on_exit = function(code, signal, client_id)
46+
vim.schedule(function()
47+
vim.call("copilot#client#LspExit", client_id, code, signal)
48+
end)
49+
end,
50+
})
51+
return id
5252
end
5353

5454
copilot.lsp_request = function(client_id, method, params, bufnr)
55-
local client = vim.lsp.get_client_by_id(client_id)
56-
if not client then
57-
return
58-
end
59-
if bufnr == vim.NIL then
60-
bufnr = nil
61-
end
62-
local _, id
63-
_, id = client.request(method, params, function(err, result)
64-
vim.call('copilot#client#LspResponse', client_id, { id = id, error = err, result = result })
65-
end, bufnr)
66-
return id
55+
local client = vim.lsp.get_client_by_id(client_id)
56+
if not client then
57+
return
58+
end
59+
if bufnr == vim.NIL then
60+
bufnr = nil
61+
end
62+
local _, id
63+
_, id = client.request(method, params, function(err, result)
64+
vim.call("copilot#client#LspResponse", client_id, { id = id, error = err, result = result })
65+
end, bufnr)
66+
return id
6767
end
6868

6969
copilot.rpc_request = function(client_id, method, params)
70-
local client = vim.lsp.get_client_by_id(client_id)
71-
if not client then
72-
return
73-
end
74-
local _, id
75-
_, id = client.rpc.request(method, params, function(err, result)
76-
vim.call('copilot#client#LspResponse', client_id, { id = id, error = err, result = result })
77-
end)
78-
return id
70+
local client = vim.lsp.get_client_by_id(client_id)
71+
if not client then
72+
return
73+
end
74+
local _, id
75+
_, id = client.rpc.request(method, params, function(err, result)
76+
vim.call("copilot#client#LspResponse", client_id, { id = id, error = err, result = result })
77+
end)
78+
return id
7979
end
8080

8181
copilot.rpc_notify = function(client_id, method, params)
82-
local client = vim.lsp.get_client_by_id(client_id)
83-
if not client then
84-
return
85-
end
86-
return client.rpc.notify(method, params)
82+
local client = vim.lsp.get_client_by_id(client_id)
83+
if not client then
84+
return
85+
end
86+
return client.rpc.notify(method, params)
8787
end
8888

8989
return copilot

0 commit comments

Comments
 (0)