Skip to content

Commit 00cd6a9

Browse files
committed
Reapply "refactor: eliminate deprecated warnings (zbirenbaum#455)"
This reverts commit 0b43549.
1 parent 0b43549 commit 00cd6a9

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

lua/copilot/api/init.lua

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ function M.request(client, method, params, callback)
1919
params.bufnr = nil
2020

2121
if callback then
22-
return client.request(method, params, callback, bufnr)
22+
return client:request(method, params, callback, bufnr)
2323
end
2424

2525
local co = coroutine.running()
26-
client.request(method, params, function(err, data, ctx)
26+
client:request(method, params, function(err, data, ctx)
2727
coroutine.resume(co, err, data, ctx)
2828
end, bufnr)
2929
return coroutine.yield()
@@ -32,12 +32,7 @@ end
3232
---@return boolean sent
3333
function M.notify(client, method, params)
3434
logger.trace("api notify:", method, params)
35-
36-
if vim.fn.has("nvim-0.11") == 1 then
37-
return client:notify(method, params)
38-
else
39-
return client.notify(method, params)
40-
end
35+
return client:notify(method, params)
4136
end
4237

4338
---@alias copilot_editor_info { name: string, version: string }

lua/copilot/client/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ function M.prepare_client_config(overrides, client)
9696
return require("copilot.client.filetypes").language_for_file_type(filetype)
9797
end,
9898
on_init = function(lsp_client, initialize_result)
99+
lsp_client = utils.wrap_client(lsp_client)
99100
if client.id == lsp_client.id then
100101
client.capabilities = initialize_result.capabilities
101102
end

lua/copilot/client/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ local M = {
2525
---@param id integer
2626
local function store_client_id(id)
2727
if M.id and M.id ~= id then
28-
if vim.lsp.get_client_by_id(M.id) then
28+
if M.get() then
2929
vim.lsp.stop_client(M.id)
3030
end
3131
end
@@ -86,7 +86,7 @@ end
8686

8787
---@return vim.lsp.Client|nil
8888
function M.get()
89-
return vim.lsp.get_client_by_id(M.id)
89+
return utils.wrap_client(vim.lsp.get_client_by_id(M.id))
9090
end
9191

9292
function M.is_disabled()

lua/copilot/client/utils.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,16 @@ function M.show_document(_, result)
8080
}
8181
end
8282

83+
M.wrap_client = function(client)
84+
if vim.fn.has("nvim-0.11") == 1 then
85+
return client
86+
end
87+
-- stylua: ignore
88+
return setmetatable({
89+
notify = function(_, ...) return client.notify(...) end,
90+
request = function(_, ...) return client.request(...) end,
91+
cancel_request = function(_, ...) return client.cancel_request(...) end,
92+
}, { __index = client })
93+
end
94+
8395
return M

lua/copilot/suggestion/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ local function cancel_inflight_requests(ctx)
186186

187187
with_client(function(client)
188188
if ctx.first then
189-
client.cancel_request(ctx.first)
189+
client:cancel_request(ctx.first)
190190
ctx.first = nil
191191
logger.trace("suggestion cancel first request")
192192
end
193193
if ctx.cycling then
194-
client.cancel_request(ctx.cycling)
194+
client:cancel_request(ctx.cycling)
195195
ctx.cycling = nil
196196
logger.trace("suggestion cancel cycling request")
197197
end

0 commit comments

Comments
 (0)