@@ -2,13 +2,17 @@ if exists('g:autoloaded_copilot')
22 finish
33endif
44let g: autoloaded_copilot = 1
5+ let g: copilot_echo_complettions = 1
56
67scriptencoding utf- 8
78
89let s: has_ghost_text = has (' nvim-0.6' ) && exists (' *nvim_buf_get_mark' )
910
1011let s: hlgroup = ' CopilotSuggestion'
1112
13+ let b: _current_copilot_suggestion_index = 0
14+ let b: _current_copilot_suggestions = {}
15+
1216if len ($XDG_CONFIG_HOME )
1317 let s: config_root = $XDG_CONFIG_HOME
1418elseif has (' win32' )
@@ -207,7 +211,7 @@ function! copilot#Complete(...) abort
207211 let doc = copilot#doc#Get ()
208212 if ! exists (' g:_copilot_completion.params.doc' ) || g: _copilot_completion .params.doc !=# doc
209213 let g: _copilot_completion =
210- \ copilot#agent#Request (' getCompletions ' , {' doc' : doc, ' options' : {}})
214+ \ copilot#agent#Request (' getCompletionsCycling ' , {' doc' : doc, ' options' : {}})
211215 let g: _copilot_last_completion = g: _copilot_completion
212216 endif
213217 let completion = g: _copilot_completion
@@ -337,14 +341,35 @@ endfunction
337341
338342function ! s: HandleTriggerResult (result) abort
339343 if exists (' a:result.completions' )
344+ if g: copilot_echo_complettions
345+ echo ' copilot:' . len (a: result .completions) . ' completions'
346+ endif
347+ let b: _current_copilot_suggestions = a: result .completions
348+ let b: _current_copilot_suggestion_index = 0
340349 let b: _copilot_suggestion = get (a: result .completions, 0 , {})
341350 else
342351 let b: _copilot_suggestion = {}
352+ let b: _current_copilot_suggestion_index = 0
353+ let b: _current_copilot_suggestions = {}
343354 endif
344355 let b: _copilot_completion = b: _copilot_suggestion
345356 call s: UpdatePreview ()
346357endfunction
347358
359+ function ! copilot#NextResult (direction)
360+ let index = b: _current_copilot_suggestion_index + a: direction
361+ if index < 0
362+ let b: _current_copilot_suggestion_index = len (b: _current_copilot_suggestions ) - 1
363+ elseif index >= len (b: _current_copilot_suggestions )
364+ let b: _current_copilot_suggestion_index = 0
365+ else
366+ let b: _current_copilot_suggestion_index = index
367+ endif
368+ let b: _copilot_suggestion = get (b: _current_copilot_suggestions , b: _current_copilot_suggestion_index , {})
369+ call s: UpdatePreview ()
370+ return " "
371+ endfunction
372+
348373function ! s: Trigger (bufnr , timer) abort
349374 let timer = get (g: , ' _copilot_timer' , -1 )
350375 unlet ! g: _copilot_timer
0 commit comments