Update 2024-11-23 16:01 OpenBSD/amd64-t14
This commit is contained in:
@@ -1,62 +1,68 @@
|
||||
local copilot = {}
|
||||
|
||||
copilot.lsp_start_client = function(cmd, handler_names)
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
local handlers = {}
|
||||
local showDocument = function(err, result, ctx, _)
|
||||
local fallback = vim.lsp.handlers['window/showDocument']
|
||||
if not fallback or (result.external and vim.g.copilot_browser) then
|
||||
return vim.fn['copilot#handlers#window_showDocument'](result)
|
||||
else
|
||||
return fallback(err, result, ctx, _)
|
||||
end
|
||||
end
|
||||
|
||||
copilot.lsp_start_client = function(cmd, handler_names, opts, settings)
|
||||
local handlers = {['window/showDocument'] = showDocument}
|
||||
local id
|
||||
for _, name in ipairs(handler_names) do
|
||||
handlers[name] = function(err, result)
|
||||
handlers[name] = function(err, result, ctx, _)
|
||||
if result then
|
||||
local retval = vim.call('copilot#agent#LspHandle', id, { method = name, params = result })
|
||||
local retval = vim.call('copilot#client#LspHandle', id, { method = name, params = result })
|
||||
if type(retval) == 'table' then
|
||||
return retval.result, retval.error
|
||||
elseif vim.lsp.handlers[name] then
|
||||
return vim.lsp.handlers[name](err, result, ctx, _)
|
||||
end
|
||||
end
|
||||
end
|
||||
if name:match('^copilot/') then
|
||||
capabilities.copilot = capabilities.copilot or {}
|
||||
capabilities.copilot[name:match('^copilot/(.*)$')] = true
|
||||
end
|
||||
end
|
||||
local workspace_folders = opts.workspaceFolders
|
||||
if #workspace_folders == 0 then
|
||||
workspace_folders = nil
|
||||
end
|
||||
id = vim.lsp.start_client({
|
||||
cmd = cmd,
|
||||
cmd_cwd = vim.call('copilot#job#Cwd'),
|
||||
name = 'copilot',
|
||||
capabilities = capabilities,
|
||||
name = 'GitHub Copilot',
|
||||
init_options = opts.initializationOptions,
|
||||
workspace_folders = workspace_folders,
|
||||
settings = settings,
|
||||
handlers = handlers,
|
||||
get_language_id = function(bufnr, filetype)
|
||||
return vim.call('copilot#doc#LanguageForFileType', filetype)
|
||||
end,
|
||||
on_init = function(client, initialize_result)
|
||||
vim.call('copilot#agent#LspInit', client.id, initialize_result)
|
||||
vim.call('copilot#client#LspInit', client.id, initialize_result)
|
||||
if vim.fn.has('nvim-0.8') == 0 then
|
||||
client.notify('workspace/didChangeConfiguration', { settings = settings })
|
||||
end
|
||||
end,
|
||||
on_exit = function(code, signal, client_id)
|
||||
vim.schedule(function()
|
||||
vim.call('copilot#agent#LspExit', client_id, code, signal)
|
||||
vim.call('copilot#client#LspExit', client_id, code, signal)
|
||||
end)
|
||||
end,
|
||||
})
|
||||
return id
|
||||
end
|
||||
|
||||
copilot.lsp_request = function(client_id, method, params)
|
||||
copilot.lsp_request = function(client_id, method, params, bufnr)
|
||||
local client = vim.lsp.get_client_by_id(client_id)
|
||||
if not client then
|
||||
return
|
||||
end
|
||||
pcall(vim.lsp.buf_attach_client, 0, client_id)
|
||||
for _, doc in ipairs({ params.doc, params.textDocument }) do
|
||||
if doc and type(doc.uri) == 'number' then
|
||||
local bufnr = doc.uri
|
||||
pcall(vim.lsp.buf_attach_client, bufnr, client_id)
|
||||
doc.uri = vim.uri_from_bufnr(bufnr)
|
||||
doc.version = vim.lsp.util.buf_versions[bufnr]
|
||||
end
|
||||
if bufnr == vim.NIL then
|
||||
bufnr = nil
|
||||
end
|
||||
local _, id
|
||||
_, id = client.request(method, params, function(err, result)
|
||||
vim.call('copilot#agent#LspResponse', client_id, { id = id, error = err, result = result })
|
||||
end)
|
||||
vim.call('copilot#client#LspResponse', client_id, { id = id, error = err, result = result })
|
||||
end, bufnr)
|
||||
return id
|
||||
end
|
||||
|
||||
@@ -67,7 +73,7 @@ copilot.rpc_request = function(client_id, method, params)
|
||||
end
|
||||
local _, id
|
||||
_, id = client.rpc.request(method, params, function(err, result)
|
||||
vim.call('copilot#agent#LspResponse', client_id, { id = id, error = err, result = result })
|
||||
vim.call('copilot#client#LspResponse', client_id, { id = id, error = err, result = result })
|
||||
end)
|
||||
return id
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user