Skip to content

Commit 1a55183

Browse files
committed
Copilot.vim 1.14.0
1 parent 5b19fb0 commit 1a55183

File tree

11 files changed

+339
-351
lines changed

11 files changed

+339
-351
lines changed

autoload/copilot.vim

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
if exists('g:autoloaded_copilot')
2-
finish
3-
endif
4-
let g:autoloaded_copilot = 1
5-
61
scriptencoding utf-8
72

83
let s:has_nvim_ghost_text = has('nvim-0.6') && exists('*nvim_buf_get_mark')
@@ -400,10 +395,10 @@ endfunction
400395

401396
function! s:Trigger(bufnr, timer) abort
402397
let timer = get(g:, '_copilot_timer', -1)
403-
unlet! g:_copilot_timer
404398
if a:bufnr !=# bufnr('') || a:timer isnot# timer || mode() !=# 'i'
405399
return
406400
endif
401+
unlet! g:_copilot_timer
407402
return copilot#Suggest()
408403
endfunction
409404

@@ -419,6 +414,7 @@ function! copilot#Schedule(...) abort
419414
endif
420415
call s:UpdatePreview()
421416
let delay = a:0 ? a:1 : get(g:, 'copilot_idle_delay', 15)
417+
call timer_stop(get(g:, '_copilot_timer', -1))
422418
let g:_copilot_timer = timer_start(delay, function('s:Trigger', [bufnr('')]))
423419
endfunction
424420

@@ -713,9 +709,10 @@ function! s:commands.version(opts) abort
713709
let info = copilot#agent#EditorInfo()
714710
echo 'copilot.vim ' .info.editorPluginInfo.version
715711
echo info.editorInfo.name . ' ' . info.editorInfo.version
716-
if exists('s:agent.node_version')
717-
echo 'dist/agent.js ' . s:agent.Call('getVersion', {}).version
718-
echo 'Node.js ' . s:agent.node_version
712+
if s:Running()
713+
let versions = s:agent.Call('getVersion', {})
714+
echo 'dist/agent.js ' . versions.version
715+
echo 'Node.js ' . get(s:agent, 'node_version', substitute(get(versions, 'runtimeVersion', '?'), '^node/', '', 'g'))
719716
call s:NodeVersionWarning()
720717
else
721718
echo 'dist/agent.js not running'

autoload/copilot/agent.vim

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
if exists('g:autoloaded_copilot_agent')
2-
finish
3-
endif
4-
let g:autoloaded_copilot_agent = 1
5-
61
scriptencoding utf-8
72

8-
let s:plugin_version = '1.13.0'
3+
let s:plugin_version = '1.14.0'
94

105
let s:error_exit = -1
116

@@ -86,7 +81,7 @@ function! s:RequestAwait() dict abort
8681
if has_key(self, 'result')
8782
return self.result
8883
endif
89-
throw 'copilot#agent(' . self.error.code . '): ' . self.error.message
84+
throw 'copilot#agent:E' . self.error.code . ': ' . self.error.message
9085
endfunction
9186

9287
function! s:RequestAgent() dict abort
@@ -240,14 +235,14 @@ function! s:RequestCancel() dict abort
240235
return self
241236
endfunction
242237

243-
function! s:DispatchMessage(agent, handler, id, params, ...) abort
238+
function! s:DispatchMessage(agent, method, handler, id, params, ...) abort
244239
try
245240
let response = {'result': call(a:handler, [a:params])}
246241
if response.result is# 0
247242
let response.result = v:null
248243
endif
249244
catch
250-
call copilot#logger#Exception()
245+
call copilot#logger#Exception('lsp.request.' . a:method)
251246
let response = {'error': {'code': -32000, 'message': v:exception}}
252247
endtry
253248
if !empty(a:id)
@@ -264,7 +259,7 @@ function! s:OnMessage(agent, body, ...) abort
264259
let id = get(request, 'id', v:null)
265260
let params = get(request, 'params', v:null)
266261
if has_key(a:agent.methods, request.method)
267-
return s:DispatchMessage(a:agent, a:agent.methods[request.method], id, params)
262+
return s:DispatchMessage(a:agent, request.method, a:agent.methods[request.method], id, params)
268263
elseif !empty(id)
269264
call s:Send(a:agent, {"id": id, "error": {"code": -32700, "message": "Method not found: " . request.method}})
270265
endif
@@ -387,6 +382,13 @@ function! s:Command() abort
387382
if !has('nvim-0.6') && v:version < 900
388383
return [v:null, '', 'Vim version too old']
389384
endif
385+
let agent = get(g:, 'copilot_agent_command', '')
386+
if empty(agent) || !filereadable(agent)
387+
let agent = s:root . '/dist/agent.js'
388+
if !filereadable(agent)
389+
return [v:null, '', 'Could not find dist/agent.js (bad install?)']
390+
endif
391+
endif
390392
let node = get(g:, 'copilot_node_command', '')
391393
if empty(node)
392394
let node = ['node']
@@ -400,9 +402,12 @@ function! s:Command() abort
400402
return [v:null, '', 'Node.js executable `' . get(node, 0, '') . "' not found"]
401403
endif
402404
endif
405+
if get(g:, 'copilot_ignore_node_version')
406+
return [node + [agent, '--stdio'], '', '']
407+
endif
403408
let node_version = s:GetNodeVersion(node)
404409
let warning = ''
405-
if !get(g:, 'copilot_ignore_node_version') && node_version.major < 18 && get(node, 0, '') !=# 'node' && executable('node')
410+
if node_version.major < 18 && get(node, 0, '') !=# 'node' && executable('node')
406411
let node_version_from_path = s:GetNodeVersion(['node'])
407412
if node_version_from_path.major >= 18
408413
let warning = 'Ignoring g:copilot_node_command: Node.js ' . node_version.string . ' is end-of-life'
@@ -421,13 +426,6 @@ function! s:Command() abort
421426
return [v:null, node_version.string, 'Node.js version 18.x or newer required but found ' . node_version.string]
422427
endif
423428
endif
424-
let agent = get(g:, 'copilot_agent_command', '')
425-
if empty(agent) || !filereadable(agent)
426-
let agent = s:root . '/dist/agent.js'
427-
if !filereadable(agent)
428-
return [v:null, node_version.string, 'Could not find dist/agent.js (bad install?)']
429-
endif
430-
endif
431429
return [node + [agent, '--stdio'], node_version.string, warning]
432430
endfunction
433431

@@ -520,7 +518,9 @@ function! copilot#agent#New(...) abort
520518
let instance.node_version_warning = command_error
521519
endif
522520
endif
523-
let instance.node_version = node_version
521+
if !empty(node_version)
522+
let instance.node_version = node_version
523+
endif
524524
if has('nvim')
525525
call extend(instance, {
526526
\ 'Close': function('s:LspClose'),

autoload/copilot/doc.vim

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
if exists('g:autoloaded_copilot_prompt')
2-
finish
3-
endif
4-
let g:autoloaded_copilot_prompt = 1
5-
61
scriptencoding utf-8
72

83
let s:slash = exists('+shellslash') ? '\' : '/'
94

10-
function copilot#doc#UTF16Width(str) abort
5+
function! copilot#doc#UTF16Width(str) abort
116
return strchars(substitute(a:str, "\\%#=2[^\u0001-\uffff]", " ", 'g'))
127
endfunction
138

@@ -60,7 +55,7 @@ let s:language_normalization_map = {
6055
\ "sh": "shellscript",
6156
\ "text": "plaintext",
6257
\ }
63-
function copilot#doc#LanguageForFileType(filetype) abort
58+
function! copilot#doc#LanguageForFileType(filetype) abort
6459
let filetype = substitute(a:filetype, '\..*', '', '')
6560
return get(s:language_normalization_map, empty(filetype) ? "text" : filetype, filetype)
6661
endfunction

autoload/copilot/job.vim

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
if exists('g:autoloaded_copilot_job')
2-
finish
3-
endif
4-
let g:autoloaded_copilot_job = 1
5-
61
scriptencoding utf-8
72

8-
function copilot#job#Nop(...) abort
3+
function! copilot#job#Nop(...) abort
94
endfunction
105

116
function! s:Jobs(job_or_jobs) abort

autoload/copilot/logger.vim

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
if exists('g:autoloaded_copilot_log')
2-
finish
3-
endif
4-
let g:autoloaded_copilot_log = 1
5-
61
if !exists('s:log_file')
72
let s:log_file = tempname() . '-copilot.log'
83
try
@@ -50,22 +45,32 @@ function! copilot#logger#Error(...) abort
5045
call copilot#logger#Raw(3, a:000)
5146
endfunction
5247

53-
function! copilot#logger#Exception() abort
48+
function! copilot#logger#Exception(...) abort
5449
if !empty(v:exception) && v:exception !=# 'Vim:Interrupt'
5550
call copilot#logger#Error('Exception: ' . v:exception . ' @ ' . v:throwpoint)
5651
let agent = copilot#RunningAgent()
5752
if !empty(agent)
53+
let [_, type, code, message; __] = matchlist(v:exception, '^\%(\(^[[:alnum:]_#]\+\)\%((\a\+)\)\=\%(\(:E-\=\d\+\)\)\=:\s*\)\=\(.*\)$')
5854
let stacklines = []
59-
for frame in split(substitute(substitute(v:throwpoint, ', \S\+ \(\d\+\)$', '[\1]', ''), '^function ', '', ''), '\.\@<!\.\.\.\@!')
60-
if frame =~# '[\/]'
61-
call add(stacklines, '[redacted]')
55+
for frame in split(substitute(v:throwpoint, ', \S\+ \(\d\+\)$', '[\1]', ''), '\.\@<!\.\.\.\@!')
56+
let fn_line = matchlist(frame, '^\%(function \)\=\(\S\+\)\[\(\d+\)\]$')
57+
if !empty(fn_line)
58+
call add(stacklines, {'function': substitute(fn_line[1], '^<SNR>\d\+_', '<SID>', ''), 'lineno': +fn_line[2]})
59+
elseif frame =~# ' Autocmds for "\*"$'
60+
call add(stacklines, {'function': frame})
61+
elseif frame =~# ' Autocmds for ".*"$'
62+
call add(stacklines, {'function': substitute(frame, ' for ".*"$', ' for "[redacted]"', '')})
6263
else
63-
call add(stacklines, substitute(frame, '^<SNR>\d\+_', '<SID>', ''))
64+
call add(stacklines, {'function': '[redacted]'})
6465
endif
6566
endfor
66-
call agent.Request('telemetry/exception', {
67-
\ 'origin': 'copilot.vim',
68-
\ 'stacktrace': join([v:exception] + stacklines, "\n")
67+
return agent.Request('telemetry/exception', {
68+
\ 'origin': a:0 ? a:1 : 'none',
69+
\ 'platform': 'other',
70+
\ 'exception_detail': [{
71+
\ 'type': type . code,
72+
\ 'value': message,
73+
\ 'stacktrace': stacklines}]
6974
\ })
7075
endif
7176
endif

autoload/copilot/panel.vim

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
if exists('g:autoloaded_copilot_panel')
2-
finish
3-
endif
4-
let g:autoloaded_copilot_panel = 1
5-
61
scriptencoding utf-8
72

83
if !exists('s:panel_id')

dist/agent.js

Lines changed: 286 additions & 285 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/agent.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/copilot.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ copilot#Accept(). Here's an example with CTRL-J:
106106
<
107107
Lua version:
108108
>
109-
vim.keymap.set('i', '<C-J>', 'copilot#Accept("\<CR>")', {
109+
vim.keymap.set('i', '<C-J>', 'copilot#Accept("\\<CR>")', {
110110
expr = true,
111111
replace_keycodes = false
112112
})

lua/_copilot.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ end
4040
copilot.lsp_request = function(client_id, method, params)
4141
local client = vim.lsp.get_client_by_id(client_id)
4242
if not client then return end
43-
vim.lsp.buf_attach_client(0, client_id)
43+
pcall(vim.lsp.buf_attach_client, 0, client_id)
4444
for _, doc in ipairs({params.doc, params.textDocument}) do
4545
if doc and type(doc.uri) == 'number' then
4646
local bufnr = doc.uri
47-
vim.lsp.buf_attach_client(bufnr, client_id)
47+
pcall(vim.lsp.buf_attach_client, bufnr, client_id)
4848
doc.uri = vim.uri_from_bufnr(bufnr)
4949
doc.version = vim.lsp.util.buf_versions[bufnr]
5050
end

0 commit comments

Comments
 (0)