@@ -12,6 +12,7 @@ local marker_prefix = "[copilot] "
12
12
local panel_uri_prefix = " copilot://"
13
13
14
14
local panel = {
15
+ --- @type vim.lsp.Client
15
16
client = nil ,
16
17
setup_done = false ,
17
18
@@ -27,6 +28,7 @@ local panel = {
27
28
filetype = nil ,
28
29
29
30
state = {
31
+ --- @type integer | nil
30
32
req_id = nil ,
31
33
line = nil ,
32
34
status = nil ,
@@ -414,7 +416,7 @@ function panel:refresh()
414
416
end
415
417
416
418
if self .state .req_id then
417
- self .client . cancel_request (self .state .req_id )
419
+ self .client : cancel_request (self .state .req_id )
418
420
self .state .req_id = nil
419
421
end
420
422
@@ -430,7 +432,6 @@ function panel:refresh()
430
432
end
431
433
432
434
self .state .received_count = type (self .state .received_count ) == " number" and self .state .received_count + 1 or 1
433
-
434
435
self :unlock ():refresh_header ():add_entry (result ):lock ()
435
436
end ,
436
437
--- @param result copilot_panel_solutions_done_data
@@ -466,31 +467,32 @@ function panel:refresh()
466
467
if not auto_refreshing and self .state .was_insert then
467
468
vim .cmd (" stopinsert" )
468
469
else
470
+ local utf16_index
469
471
-- assume cursor at end of line
470
- local _ , utf16_index = vim .str_utfindex (self .state .line , " utf-16" )
472
+ if vim .has (" nvim-0.11" ) then
473
+ utf16_index = vim .str_utfindex (self .state .line , " utf-16" )
474
+ else
475
+ --- @diagnostic disable-next-line : missing-parameter
476
+ _ , utf16_index = vim .str_utfindex (self .state .line )
477
+ end
471
478
params .doc .position .character = utf16_index
472
479
params .position .character = params .doc .position .character
473
480
end
474
481
475
482
-- on_solutions_done can be invoked before the api.get_panel_completions callback
476
483
self .state .status = " loading"
477
484
478
- local _ , id = api .get_panel_completions (
479
- self .client ,
480
- params ,
481
- --- @param result copilot_get_panel_completions_data
482
- function (err , result )
483
- if err then
484
- self .state .status = " error"
485
- self .state .error = err
486
- logger .error (self .state .error )
487
- return
488
- end
489
-
490
- self .state .expected_count = result .solutionCountTarget
491
- panel :unlock ():refresh_header ():lock ()
485
+ local _ , id = api .get_panel_completions (self .client , params , function (err , result )
486
+ if err then
487
+ self .state .status = " error"
488
+ self .state .error = err
489
+ logger .error (self .state .error )
490
+ return
492
491
end
493
- )
492
+
493
+ self .state .expected_count = result .solutionCountTarget
494
+ panel :unlock ():refresh_header ():lock ()
495
+ end )
494
496
495
497
self .state .req_id = id
496
498
end
0 commit comments