Skip to content

Commit da286d8

Browse files
committed
Copilot.vim 1.5.0
1 parent 6c5abda commit da286d8

File tree

5 files changed

+82
-38
lines changed

5 files changed

+82
-38
lines changed

README.md

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,65 @@
11
# Copilot.vim
22

33
GitHub Copilot uses OpenAI Codex to suggest code and entire functions in
4-
real-time right from your editor. Trained on billions of lines of public code,
5-
GitHub Copilot turns natural language prompts including comments and method
6-
names into coding suggestions across dozens of languages.
4+
real-time right from your editor. Trained on billions of lines of public
5+
code, GitHub Copilot turns natural language prompts including comments and
6+
method names into coding suggestions across dozens of languages.
77

8-
Copilot.vim is a Vim plugin for GitHub Copilot. For now, it requires Neovim
9-
0.6 (for virtual lines support) and a Node.js installation.
8+
Copilot.vim is a Vim/Neovim plugin for GitHub Copilot.
109

1110
To learn more, visit
1211
[github.com/features/copilot](https://github.com/features/copilot).
1312

1413
## Subscription
1514

16-
GitHub Copilot requires a subscription. It is free for verified students and
15+
GitHub Copilot requires a subscription. It is free for verified students and
1716
maintainers of popular open source projects on GitHub.
1817

18+
GitHub Copilot is subject to the [GitHub Additional Product
19+
Terms](https://docs.github.com/en/site-policy/github-terms/github-terms-for-additional-products-and-features).
20+
1921
## Getting started
2022

21-
1. Install [Neovim][].
23+
1. Install [Neovim][] or the latest patch of [Vim][] (9.0.0162 or newer).
2224

2325
2. Install [Node.js][] version 16. (Other versions should work too, except
2426
Node 18 which isn't supported yet.)
2527

2628
3. Install `github/copilot.vim` using vim-plug, packer.nvim, or any other
27-
plugin manager. Or to install directly:
29+
plugin manager. Or to install manually, run one of the following
30+
commands:
31+
32+
* Vim, Linux/macOS:
33+
34+
git clone https://github.com/github/copilot.vim.git \
35+
~/.vim/pack/github/start/copilot.vim
36+
37+
* Neovim, Linux/macOS:
38+
39+
git clone https://github.com/github/copilot.vim.git \
40+
~/.config/nvim/pack/github/start/copilot.vim
2841

29-
git clone https://github.com/github/copilot.vim.git \
30-
~/.config/nvim/pack/github/start/copilot.vim
42+
* Vim, Windows (PowerShell command):
43+
44+
git clone https://github.com/github/copilot.vim.git `
45+
$HOME/vimfiles/pack/github/start/copilot.vim
46+
47+
* Neovim, Windows (PowerShell command):
48+
49+
git clone https://github.com/github/copilot.vim.git `
50+
$HOME/AppData/Local/nvim/pack/github/start/copilot.vim
3151

3252
4. Start Neovim and invoke `:Copilot setup`.
3353

3454
[Node.js]: https://nodejs.org/en/download/
3555
[Neovim]: https://github.com/neovim/neovim/releases/latest
56+
[Vim]: https://github.com/vim/vim
3657

3758
Suggestions are displayed inline and can be accepted by pressing the tab key.
3859
See `:help copilot` for more information.
3960

40-
GitHub Copilot is subject to the [GitHub Additional Product
41-
Terms](https://docs.github.com/en/site-policy/github-terms/github-terms-for-additional-products-and-features).
42-
43-
4461
## Troubleshooting
4562

46-
We’d love to get your help in making GitHub Copilot better! If you have
63+
We’d love to get your help in making GitHub Copilot better! If you have
4764
feedback or encounter any problems, please reach out on our [Feedback
4865
forum](https://github.com/github-community/community/discussions/categories/copilot).

autoload/copilot.vim

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,19 @@ let g:autoloaded_copilot = 1
55

66
scriptencoding utf-8
77

8-
let s:has_ghost_text = has('nvim-0.6') && exists('*nvim_buf_get_mark')
8+
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.0162') && has('textprop')
10+
let s:has_ghost_text = s:has_nvim_ghost_text || s:has_vim_ghost_text
911

1012
let s:hlgroup = 'CopilotSuggestion'
13+
let s:annot_hlgroup = 'CopilotAnnotation'
14+
15+
if s:has_vim_ghost_text && empty(prop_type_get(s:hlgroup))
16+
call prop_type_add(s:hlgroup, {'highlight': s:hlgroup})
17+
endif
18+
if s:has_vim_ghost_text && empty(prop_type_get(s:annot_hlgroup))
19+
call prop_type_add(s:annot_hlgroup, {'highlight': s:annot_hlgroup})
20+
endif
1121

1222
if len($XDG_CONFIG_HOME)
1323
let s:config_root = $XDG_CONFIG_HOME
@@ -205,15 +215,16 @@ function! s:SuggestionTextWithAdjustments() abort
205215
return ['', 0, 0, '']
206216
endif
207217
let typed = strpart(line, 0, offset)
208-
let delete = strchars(strpart(line, offset))
218+
let delete = strpart(line, offset)
209219
let uuid = get(choice, 'uuid', '')
210-
if typed ==# strpart(choice.text, 0, offset)
211-
return [strpart(choice.text, offset), 0, delete, uuid]
212-
elseif typed =~# '^\s*$'
220+
if typed =~# '^\s*$'
213221
let leading = matchstr(choice.text, '^\s\+')
214-
if strpart(typed, 0, len(leading)) == leading
215-
return [strpart(choice.text, len(leading)), len(typed) - len(leading), delete, uuid]
222+
let unindented = strpart(choice.text, len(leading))
223+
if strpart(typed, 0, len(leading)) == leading && unindented !=# delete
224+
return [unindented, len(typed) - len(leading), strchars(delete), uuid]
216225
endif
226+
elseif typed ==# strpart(choice.text, 0, offset)
227+
return [strpart(choice.text, offset), 0, strchars(delete), uuid]
217228
endif
218229
catch
219230
call copilot#logger#Exception()
@@ -330,8 +341,11 @@ function! s:WindowPreview(lines, outdent, delete, ...) abort
330341
endfunction
331342

332343
function! s:ClearPreview() abort
333-
if exists('*nvim_buf_del_extmark')
344+
if s:has_nvim_ghost_text
334345
call nvim_buf_del_extmark(0, copilot#NvimNs(), 1)
346+
elseif s:has_vim_ghost_text
347+
call prop_remove({'type': s:hlgroup, 'all': v:true})
348+
call prop_remove({'type': s:annot_hlgroup, 'all': v:true})
335349
endif
336350
endfunction
337351

@@ -349,24 +363,36 @@ function! s:UpdatePreview() abort
349363
return s:ClearPreview()
350364
endif
351365
if exists('b:_copilot.cycling_callbacks')
352-
let annot = [[' '], ['(1/…)', 'CopilotAnnotation']]
366+
let annot = '(1/…)'
353367
elseif exists('b:_copilot.cycling')
354-
let annot = [[' '], ['(' . (b:_copilot.choice + 1) . '/' . len(b:_copilot.suggestions) . ')', 'CopilotAnnotation']]
368+
let annot = '(' . (b:_copilot.choice + 1) . '/' . len(b:_copilot.suggestions) . ')'
355369
else
356-
let annot = []
370+
let annot = ''
357371
endif
358-
let data = {'id': 1}
359-
let data.virt_text_win_col = virtcol('.') - 1
360-
let data.virt_text = [[text[0] . repeat(' ', delete - len(text[0])), s:hlgroup]]
361-
if len(text) > 1
362-
let data.virt_lines = map(text[1:-1], { _, l -> [[l, s:hlgroup]] })
363-
let data.virt_lines[-1] += annot
372+
call s:ClearPreview()
373+
if s:has_nvim_ghost_text
374+
let data = {'id': 1}
375+
let data.virt_text_win_col = virtcol('.') - 1
376+
let data.virt_text = [[text[0] . repeat(' ', delete - len(text[0])), s:hlgroup]]
377+
if len(text) > 1
378+
let data.virt_lines = map(text[1:-1], { _, l -> [[l, s:hlgroup]] })
379+
if !empty(annot)
380+
let data.virt_lines[-1] += [[' '], [annot, s:annot_hlgroup]]
381+
endif
382+
elseif len(annot)
383+
let data.virt_text += [[' '], [annot, s:annot_hlgroup]]
384+
endif
385+
let data.hl_mode = 'combine'
386+
call nvim_buf_set_extmark(0, copilot#NvimNs(), line('.')-1, col('.')-1, data)
364387
else
365-
let data.virt_text += annot
388+
call prop_add(line('.'), col('.'), {'type': s:hlgroup, 'text': text[0]})
389+
for line in text[1:]
390+
call prop_add(line('.'), col('.'), {'type': s:hlgroup, 'text_align': 'below', 'text': line})
391+
endfor
392+
if !empty(annot)
393+
call prop_add(line('.'), col('$'), {'type': s:annot_hlgroup, 'text': ' ' . annot[1][0]})
394+
endif
366395
endif
367-
let data.hl_mode = 'combine'
368-
call nvim_buf_del_extmark(0, copilot#NvimNs(), 1)
369-
call nvim_buf_set_extmark(0, copilot#NvimNs(), line('.')-1, col('.')-1, data)
370396
if uuid !=# get(s:, 'uuid', '')
371397
let s:uuid = uuid
372398
call copilot#Request('notifyShown', {'uuid': uuid})

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.4.3'
8+
let s:plugin_version = '1.5.0'
99

1010
let s:error_exit = -1
1111

copilot/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.

plugin/copilot.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function! s:ColorScheme() abort
1717
else
1818
hi def CopilotSuggestion guifg=#808080 ctermfg=8
1919
endif
20+
hi def link CopilotAnnotation Normal
2021
endfunction
2122

2223
function! s:MapTab() abort

0 commit comments

Comments
 (0)