Skip to content

Commit f6cdb5c

Browse files
committed
Copilot.vim 1.3.1
1 parent df203c1 commit f6cdb5c

File tree

6 files changed

+42
-19
lines changed

6 files changed

+42
-19
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ Service](https://docs.github.com/en/github/site-policy/github-terms-of-service#j
2525

2626
## Getting started
2727

28-
1. Install [Node.js][] 12 or newer.
28+
1. Install [Neovim][].
2929

30-
2. Install [Neovim][] 0.6 or newer.
30+
2. Install [Node.js][] version 16. (Other versions should work too, except
31+
Node 18 which isn't supported yet.)
3132

3233
3. Install `github/copilot.vim` using vim-plug, packer.nvim, or any other
3334
plugin manager. Or to install directly:

autoload/copilot.vim

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ function! copilot#Clear() abort
198198
endfunction
199199

200200
function! copilot#Dismiss() abort
201-
unlet! b:_copilot
202201
call copilot#Clear()
203202
return ''
204203
endfunction
@@ -494,7 +493,6 @@ function! copilot#Schedule(...) abort
494493
endfunction
495494

496495
function! copilot#OnInsertLeave() abort
497-
unlet! b:_copilot
498496
return copilot#Clear()
499497
endfunction
500498

autoload/copilot/agent.vim

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ let g:autoloaded_copilot_agent = 1
55

66
scriptencoding utf-8
77

8-
let s:plugin_version = '1.3.0'
8+
let s:plugin_version = '1.3.1'
99

1010
let s:error_exit = -1
1111

1212
let s:root = expand('<sfile>:h:h:h')
1313

14-
let s:instances = {}
14+
if !exists('s:instances')
15+
let s:instances = {}
16+
endif
1517

1618
let s:jobstop = function(exists('*jobstop') ? 'jobstop' : 'job_stop')
1719
function! s:Kill(agent, ...) abort
@@ -119,6 +121,7 @@ endfunction
119121
function! s:AgentCancel(request) dict abort
120122
if has_key(self.requests, get(a:request, 'id', ''))
121123
call remove(self.requests, a:request.id)
124+
call self.Notify('$/cancelRequest', {'id': a:request.id})
122125
endif
123126
if get(a:request, 'status', '') ==# 'running'
124127
let a:request.status = 'canceled'
@@ -132,6 +135,7 @@ function! s:RequestCancel() dict abort
132135
elseif get(self, 'status', '') ==# 'running'
133136
let self.status = 'canceled'
134137
endif
138+
return self
135139
endfunction
136140

137141
function! s:DispatchMessage(agent, handler, id, params, ...) abort
@@ -272,32 +276,38 @@ function! s:IsArmMacOS() abort
272276
endfunction
273277

274278
function! s:Command() abort
275-
if !has('nvim-0.5') && v:version < 802
279+
if !has('nvim-0.6') && v:version < 802
276280
return [v:null, 'Vim version too old']
277281
endif
278-
let node = get(g:, 'copilot_node_command', 'node')
279-
if type(node) == type('')
280-
let node = [node]
282+
let node = get(g:, 'copilot_node_command', '')
283+
if empty(node)
284+
let node = ['node']
285+
elseif type(node) == type('')
286+
let node = [expand(node)]
281287
endif
282288
if !executable(get(node, 0, ''))
283289
if get(node, 0, '') ==# 'node'
284-
return [v:null, 'Node not found in PATH']
290+
return [v:null, 'Node.js not found in PATH']
285291
else
286-
return [v:null, 'Node executable `' . get(node, 0, '') . "' not found"]
292+
return [v:null, 'Node.js executable `' . get(node, 0, '') . "' not found"]
287293
endif
288294
endif
289295
let out = []
290296
let err = []
291297
let status = copilot#job#Stream(node + ['--version'], function('add', [out]), function('add', [err]))
292298
if status != 0
293-
return [v:null, 'Node exited with status ' . status]
299+
return [v:null, 'Node.js exited with status ' . status]
294300
endif
295-
let major = +matchstr(join(out, ''), '^v\zs\d\+\ze\.')
301+
let node_version = matchstr(join(out, ''), '^v\zs\d\+\.[^[:space:]]*')
302+
let major = str2nr(node_version)
303+
let too_new = major >= 18 && node_version !=# '18.0.0'
296304
if !get(g:, 'copilot_ignore_node_version')
297-
if major < 16 && s:IsArmMacOS()
298-
return [v:null, 'Node v16+ required on Apple Silicon but found ' . get(out, 0, 'nothing')]
299-
elseif major < 12
300-
return [v:null, 'Node v12+ required but found ' . get(out, 0, 'nothing')]
305+
if major == 0
306+
return [v:null, 'Could not determine Node.js version']
307+
elseif (major < 16 || too_new) && s:IsArmMacOS()
308+
return [v:null, 'Node.js version 16.x or 17.x required on Apple Silicon but found ' . node_version]
309+
elseif major < 12 || too_new
310+
return [v:null, 'Node.js version 12.x–17.x required but found ' . node_version]
301311
endif
302312
endif
303313
let agent = s:root . '/copilot/dist/agent.js'

autoload/copilot/job.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ function! copilot#job#Stream(argv, out_cb, err_cb, ...) abort
7979
if exists('*job_start')
8080
let result = {}
8181
let job = job_start(a:argv, {
82+
\ 'cwd': expand("~"),
8283
\ 'out_mode': 'raw',
8384
\ 'out_cb': { j, d -> OutCb(d) },
8485
\ 'err_cb': { j, d -> ErrCb(d) },
@@ -87,6 +88,7 @@ function! copilot#job#Stream(argv, out_cb, err_cb, ...) abort
8788
\ })
8889
else
8990
let jopts = {
91+
\ 'cwd': expand("~"),
9092
\ 'stderr': [''],
9193
\ 'on_stdout': { j, d, t -> OutCb(join(d, "\n")) },
9294
\ 'on_stderr': function('s:NvimCallback', [ErrCb]),

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.

doc/copilot.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,17 @@ after/colors/<colorschemename>.vim in your 'runtimepath' (e.g.,
102102
~/.config/nvim/after/colors/solarized.vim). Example declaration:
103103
>
104104
highlight CopilotSuggestion guifg=#555555 ctermfg=8
105+
<
106+
CONFIGURATION *copilot-configuration*
107+
108+
*g:copilot_node_command*
109+
Tell Copilot what `node` binary to use with g:copilot_node_command.
110+
This is useful if the `node` in your PATH is an unsupported version.
111+
>
112+
let g:copilot_node_command = "~/.nodenv/versions/16.15.0/bin/node"
113+
<
114+
Lua version:
115+
>
116+
vim.g.copilot_node_command = "$NVM_DIR/versions/node/v16.15.0/bin/node"
105117
<
106118
vim:tw=78:et:ft=help:norl:

0 commit comments

Comments
 (0)