@@ -6,15 +6,19 @@ local print_buf = require("copilot.extensions.print_panel")
66local 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
1315panel .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 )
1822end
1923
2024local existing_matches = {}
2731panel .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 })
5454end )
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 ()
0 commit comments