@@ -12,6 +12,7 @@ local marker_prefix = "[copilot] "
1212local panel_uri_prefix = " copilot://"
1313
1414local panel = {
15+ --- @type vim.lsp.Client
1516 client = nil ,
1617 setup_done = false ,
1718
@@ -27,6 +28,7 @@ local panel = {
2728 filetype = nil ,
2829
2930 state = {
31+ --- @type integer | nil
3032 req_id = nil ,
3133 line = nil ,
3234 status = nil ,
@@ -414,7 +416,7 @@ function panel:refresh()
414416 end
415417
416418 if self .state .req_id then
417- self .client . cancel_request (self .state .req_id )
419+ self .client : cancel_request (self .state .req_id )
418420 self .state .req_id = nil
419421 end
420422
@@ -430,7 +432,6 @@ function panel:refresh()
430432 end
431433
432434 self .state .received_count = type (self .state .received_count ) == " number" and self .state .received_count + 1 or 1
433-
434435 self :unlock ():refresh_header ():add_entry (result ):lock ()
435436 end ,
436437 --- @param result copilot_panel_solutions_done_data
@@ -466,31 +467,32 @@ function panel:refresh()
466467 if not auto_refreshing and self .state .was_insert then
467468 vim .cmd (" stopinsert" )
468469 else
470+ local utf16_index
469471 -- 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
471478 params .doc .position .character = utf16_index
472479 params .position .character = params .doc .position .character
473480 end
474481
475482 -- on_solutions_done can be invoked before the api.get_panel_completions callback
476483 self .state .status = " loading"
477484
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
492491 end
493- )
492+
493+ self .state .expected_count = result .solutionCountTarget
494+ panel :unlock ():refresh_header ():lock ()
495+ end )
494496
495497 self .state .req_id = id
496498end
0 commit comments