Skip to content

Commit 3417fde

Browse files
committed
fix and improve cmp panel completions
1 parent a535c5e commit 3417fde

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

lua/copilot/extensions/panel.lua

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ local print_buf = require("copilot.extensions.print_panel")
66
local panel = {
77
method = "getPanelCompletions",
88
usecmp = false,
9+
client = vim.lsp.get_active_clients({name="copilot"})[1],
910
buf = "",
1011
uri = "copilot:///placeholder",
12+
requests = {},
1113
}
1214

1315
panel.send_request = function (callback)
16+
panel.client = not vim.tbl_isempty(panel.client) and panel.client or vim.lsp.get_active_clients({name="copilot"})[1]
17+
if not panel.client then return end
1418
local completion_params = util.get_completion_params()
1519
completion_params.panelId = panel.uri
1620
callback = callback or function () end
17-
vim.lsp.buf_request(0, panel.method, completion_params, callback)
21+
return panel.client.rpc.request(panel.method, completion_params, callback)
1822
end
1923

2024
local existing_matches= {}
@@ -27,15 +31,12 @@ end
2731
panel.complete = vim.schedule_wrap(function (_, params, callback)
2832
local context = params.context
2933
verify_existing(context)
34+
local sent, id
3035

3136
local add_completion = function (result)
3237
result.text = result.displayText
3338
local formatted = format.format_item(params, result)
3439
existing_matches[context.bufnr][context.cursor.row][formatted.label] = formatted
35-
callback({
36-
isIncomplete = true,
37-
items = vim.tbl_values(existing_matches[context.bufnr][context.cursor.row])
38-
})
3940
end
4041

4142
local completed = function ()
@@ -47,9 +48,8 @@ panel.complete = vim.schedule_wrap(function (_, params, callback)
4748

4849
handler.add_handler_callback("PanelSolution", "cmp", add_completion)
4950
handler.add_handler_callback("PanelSolutionsDone", "cmp", completed)
50-
51-
panel.send_request()
52-
51+
if sent and id then panel.client.rpc.cancel_request(id) end
52+
sent, id = panel.send_request()
5353
callback({ isIncomplete = true })
5454
end)
5555

@@ -58,6 +58,7 @@ function panel.create (max_results)
5858
panel.buf = type(panel.uri) == "number" or vim.api.nvim_create_buf(false, true)
5959
vim.api.nvim_buf_set_name(panel.buf, "copilot:///" .. tostring(panel.buf))
6060
panel.uri = vim.uri_from_bufnr(panel.buf)
61+
panel.client = vim.lsp.get_active_clients({name="copilot"})
6162

6263
vim.api.nvim_create_user_command("CopilotPanel", function ()
6364
panel.send_request()

lua/copilot/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ local client = require("copilot.client")
33

44
local defaults = {
55
cmp = {
6-
method = "getCompletionsCycling",
6+
method = "getPanelCompletions",
77
max_results = 5,
88
},
99
extensions = {
1010
getPanelCompletions = function ()
11-
require("copilot_cmp").setup(require("copilot.panel").complete)
11+
require("copilot_cmp").setup(require("copilot.extensions.panel").complete)
1212
end,
1313
getCompletionsCycling = function ()
1414
require("copilot_cmp").setup()

0 commit comments

Comments
 (0)