Skip to content

Commit 5e9d4dc

Browse files
committed
Copilot.vim 1.4.1
1 parent aa9e451 commit 5e9d4dc

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

autoload/copilot.vim

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,6 @@ function! s:commands.feedback(opts) abort
702702
endif
703703
endfunction
704704

705-
function! s:commands.log(opts) abort
706-
return a:opts.mods . ' split +$ ' . fnameescape(copilot#logger#File())
707-
endfunction
708-
709705
function! s:commands.restart(opts) abort
710706
call s:Stop()
711707
let err = copilot#Agent().StartupError()
@@ -759,10 +755,13 @@ endfunction
759755

760756
function! copilot#Command(line1, line2, range, bang, mods, arg) abort
761757
let cmd = matchstr(a:arg, '^\%(\\.\|\S\)\+')
758+
let arg = matchstr(a:arg, '\s\zs\S.*')
759+
if cmd ==# 'log'
760+
return a:mods . ' split +$ ' . fnameescape(copilot#logger#File())
761+
endif
762762
if !empty(cmd) && !has_key(s:commands, tr(cmd, '-', '_'))
763763
return 'echoerr ' . string('Copilot: unknown command ' . string(cmd))
764764
endif
765-
let arg = matchstr(a:arg, '\s\zs\S.*')
766765
try
767766
let err = copilot#Agent().StartupError()
768767
if !empty(err)

autoload/copilot/agent.vim

Lines changed: 15 additions & 5 deletions
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.0'
8+
let s:plugin_version = '1.4.1'
99

1010
let s:error_exit = -1
1111

@@ -259,7 +259,12 @@ endfunction
259259

260260
function! s:OnExit(agent, code) abort
261261
let a:agent.exit_status = a:code
262-
unlet! a:agent.job
262+
if has_key(a:agent, 'job')
263+
call remove(a:agent, 'job')
264+
endif
265+
if has_key(a:agent, 'client_id')
266+
call remove(a:agent, 'client_id')
267+
endif
263268
for id in sort(keys(a:agent.requests), { a, b -> +a > +b })
264269
let request = remove(a:agent.requests, id)
265270
if request.status ==# 'canceled'
@@ -284,15 +289,14 @@ function! copilot#agent#LspInit(agent_id, initialize_result) abort
284289
return
285290
endif
286291
let instance = s:instances[a:agent_id]
287-
call s:GetCapabilitiesResult(a:initialize_result, instance)
292+
call timer_start(0, { _ -> s:GetCapabilitiesResult(a:initialize_result, instance)})
288293
endfunction
289294

290295
function! copilot#agent#LspExit(agent_id, code, signal) abort
291296
if !has_key(s:instances, a:agent_id)
292297
return
293298
endif
294299
let instance = remove(s:instances, a:agent_id)
295-
unlet! instance.client_id
296300
call s:OnExit(instance, a:code)
297301
endfunction
298302

@@ -305,7 +309,13 @@ endfunction
305309

306310
function! s:LspRequest(method, params, ...) dict abort
307311
let id = v:lua.require'_copilot'.lsp_request(self.id, a:method, a:params)
308-
return call('s:SetUpRequest', [self, id, a:method, a:params] + a:000)
312+
if id isnot# v:null
313+
return call('s:SetUpRequest', [self, id, a:method, a:params] + a:000)
314+
endif
315+
if has_key(self, 'client_id')
316+
call copilot#agent#LspExit(self.client_id, -1, -1)
317+
endif
318+
throw 'copilot#agent: LSP client not available'
309319
endfunction
310320

311321
function! s:LspClose() dict abort

copilot/dist/agent.js

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

lua/_copilot.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,31 @@ copilot.lsp_start_client = function(cmd, handler_names)
2929
end
3030

3131
copilot.lsp_request = function(client_id, method, params, bufnr)
32+
local client = vim.lsp.get_client_by_id(client_id)
33+
if not client then return end
3234
bufnr = bufnr or 0
3335
vim.lsp.buf_attach_client(bufnr, client_id)
34-
params.uri = vim.uri_from_bufnr(bufnr)
3536
local _, id
36-
_, id = vim.lsp.get_client_by_id(client_id).request(method, params, function(err, result)
37+
_, id = client.request(method, params, function(err, result)
3738
vim.call('copilot#agent#LspResponse', client_id, {id = id, error = err, result = result}, bufnr)
3839
end)
3940
return id
4041
end
4142

4243
copilot.rpc_request = function(client_id, method, params)
44+
local client = vim.lsp.get_client_by_id(client_id)
45+
if not client then return end
4346
local _, id
44-
_, id = vim.lsp.get_client_by_id(client_id).rpc.request(method, params, function(err, result)
47+
_, id = client.rpc.request(method, params, function(err, result)
4548
vim.call('copilot#agent#LspResponse', client_id, {id = id, error = err, result = result})
4649
end)
4750
return id
4851
end
4952

5053
copilot.rpc_notify = function(client_id, method, params)
51-
return vim.lsp.get_client_by_id(client_id).rpc.notify(method, params)
54+
local client = vim.lsp.get_client_by_id(client_id)
55+
if not client then return end
56+
return client.rpc.notify(method, params)
5257
end
5358

5459
return copilot

0 commit comments

Comments
 (0)