@@ -6,7 +6,8 @@ let g:autoloaded_copilot = 1
66scriptencoding utf- 8
77
88let s: has_nvim_ghost_text = has (' nvim-0.6' ) && exists (' *nvim_buf_get_mark' )
9- let s: has_vim_ghost_text = has (' patch-9.0.0185' ) && has (' textprop' )
9+ let s: vim_minimum_version = ' 9.0.0185'
10+ let s: has_vim_ghost_text = has (' patch-' . s: vim_minimum_version ) && has (' textprop' )
1011let s: has_ghost_text = s: has_nvim_ghost_text || s: has_vim_ghost_text
1112
1213let s: hlgroup = ' CopilotSuggestion'
@@ -201,31 +202,22 @@ function! s:SuggestionTextWithAdjustments() abort
201202 endif
202203 let line = getline (' .' )
203204 let offset = col (' .' ) - 1
204- if choice.range .start .character != 0
205- call copilot#logger#Warn (' unexpected range ' . json_encode (choice.range ))
206- return [' ' , 0 , 0 , ' ' ]
207- endif
205+ let choice_text = strpart (line , 0 , copilot#doc#UTF16ToByteIdx (line , choice.range .start .character )) . choice.text
208206 let typed = strpart (line , 0 , offset)
209- if exists (' *utf16idx' )
210- let end_offset = byteidx (line , choice.range .end .character , 1 )
211- elseif has (' nvim' )
212- let end_offset = v: lua .vim .str_byteindex (line , choice.range .end .character , 1 )
213- else
207+ let end_offset = copilot#doc#UTF16ToByteIdx (line , choice.range .end .character )
208+ if end_offset < 0
214209 let end_offset = len (line )
215- while copilot#doc#UTF16Width (strpart (line , 0 , end_offset)) > choice.range .end .character && end_offset > 0
216- let end_offset -= 1
217- endwhile
218210 endif
219211 let delete = strpart (line , offset, end_offset - offset)
220212 let uuid = get (choice, ' uuid' , ' ' )
221213 if typed = ~# ' ^\s*$'
222- let leading = matchstr (choice.text , ' ^\s\+' )
223- let unindented = strpart (choice.text , len (leading))
214+ let leading = matchstr (choice_text , ' ^\s\+' )
215+ let unindented = strpart (choice_text , len (leading))
224216 if strpart (typed, 0 , len (leading)) == leading && unindented !=# delete
225217 return [unindented, len (typed) - len (leading), strchars (delete ), uuid]
226218 endif
227- elseif typed == # strpart (choice.text , 0 , offset)
228- return [strpart (choice.text , offset), 0 , strchars (delete ), uuid]
219+ elseif typed == # strpart (choice_text , 0 , offset)
220+ return [strpart (choice_text , offset), 0 , strchars (delete ), uuid]
229221 endif
230222 catch
231223 call copilot#logger#Exception ()
@@ -535,7 +527,11 @@ let s:commands = {}
535527function ! s: EnabledStatusMessage () abort
536528 let buf_disabled = s: BufferDisabled ()
537529 if ! s: has_ghost_text && bufwinid (' copilot://' ) == -1
538- return " Neovim 0.6 required to support ghost text"
530+ if has (' nvim' )
531+ return " Neovim 0.6 required to support ghost text"
532+ else
533+ return " Vim " . s: vim_minimum_version . " required to support ghost text"
534+ endif
539535 elseif ! copilot#IsMapped ()
540536 return ' <Tab> map has been disabled or is claimed by another plugin'
541537 elseif ! get (g: , ' copilot_enabled' , 1 )
0 commit comments