@@ -121,11 +121,15 @@ function! copilot#Clear() abort
121121endfunction
122122
123123function ! s: Reject (bufnr ) abort
124- let uuid = getbufvar (a: bufnr , ' _copilot_uuid' )
125- if ! empty (uuid)
126- call setbufvar (a: bufnr , ' _copilot_uuid' , ' ' )
127- call copilot#Request (' notifyRejected' , {' uuids' : [uuid]})
128- endif
124+ try
125+ let dict = getbufvar (a: bufnr , ' _copilot' )
126+ if type (dict ) == v: t_dict && ! empty (get (dict , ' shown_choices' , {}))
127+ call copilot#Request (' notifyRejected' , {' uuids' : keys (dict .shown_choices)})
128+ let dict .shown_choices = {}
129+ endif
130+ catch
131+ call copilot#logger#Exception ()
132+ endtry
129133endfunction
130134
131135function ! copilot#Dismiss () abort
@@ -350,9 +354,8 @@ function! s:UpdatePreview() abort
350354 call prop_add (line (' .' ), col (' $' ), {' type' : s: annot_hlgroup , ' text' : ' ' . annot})
351355 endif
352356 endif
353- if uuid !=# get (b: , ' _copilot_uuid' , ' ' )
354- call s: Reject (' %' )
355- let b: _copilot_uuid = uuid
357+ if ! has_key (b: _copilot .shown_choices, uuid)
358+ let b: _copilot .shown_choices[uuid] = v: true
356359 call copilot#Request (' notifyShown' , {' uuid' : uuid})
357360 endif
358361 catch
@@ -366,6 +369,7 @@ function! s:HandleTriggerResult(result) abort
366369 endif
367370 let b: _copilot .suggestions = get (a: result , ' completions' , [])
368371 let b: _copilot .choice = 0
372+ let b: _copilot .shown_choices = {}
369373 call s: UpdatePreview ()
370374endfunction
371375
@@ -441,7 +445,6 @@ function! copilot#Accept(...) abort
441445 let s = copilot#GetDisplayedSuggestion ()
442446 if ! empty (s .text)
443447 unlet ! b: _copilot
444- let b: _copilot_uuid = ' '
445448 call copilot#Request (' notifyAccepted' , {' uuid' : s .uuid})
446449 call s: ClearPreview ()
447450 let s: suggestion_text = s .text
0 commit comments