Skip to content

Commit 97a9f1a

Browse files
committed
Copilot.vim 1.9.3
1 parent 4a361e8 commit 97a9f1a

File tree

5 files changed

+49
-21
lines changed

5 files changed

+49
-21
lines changed

autoload/copilot.vim

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ let g:autoloaded_copilot = 1
66
scriptencoding utf-8
77

88
let 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')
1011
let s:has_ghost_text = s:has_nvim_ghost_text || s:has_vim_ghost_text
1112

1213
let 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 = {}
535527
function! 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)

autoload/copilot/agent.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let g:autoloaded_copilot_agent = 1
55

66
scriptencoding utf-8
77

8-
let s:plugin_version = '1.9.2'
8+
let s:plugin_version = '1.9.3'
99

1010
let s:error_exit = -1
1111

autoload/copilot/doc.vim

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,38 @@ function copilot#doc#UTF16Width(str) abort
1111
return strchars(substitute(a:str, "\\%#=2[^\u0001-\uffff]", " ", 'g'))
1212
endfunction
1313

14+
if exists('*utf16idx')
15+
16+
function! copilot#doc#UTF16ToByteIdx(str, utf16_idx) abort
17+
return byteidx(a:str, a:utf16_idx, 1)
18+
endfunction
19+
20+
elseif has('nvim')
21+
22+
function! copilot#doc#UTF16ToByteIdx(str, utf16_idx) abort
23+
try
24+
return v:lua.vim.str_byteindex(a:str, a:utf16_idx, 1)
25+
catch /^Vim(return):E5108:/
26+
return -1
27+
endtry
28+
endfunction
29+
30+
else
31+
32+
function! copilot#doc#UTF16ToByteIdx(str, utf16_idx) abort
33+
if copilot#doc#UTF16Width(a:str) < a:utf16_idx
34+
return -1
35+
endif
36+
let end_offset = len(a:str)
37+
while copilot#doc#UTF16Width(strpart(a:str, 0, end_offset)) > a:utf16_idx && end_offset > 0
38+
let end_offset -= 1
39+
endwhile
40+
return end_offset
41+
endfunction
42+
43+
endif
44+
45+
1446
let s:language_normalization_map = {
1547
\ "bash": "shellscript",
1648
\ "bst": "bibtex",

dist/agent.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/agent.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)