Skip to content

Commit 46bb2e7

Browse files
committed
upd
1 parent 1829a02 commit 46bb2e7

File tree

16 files changed

+3102
-9
lines changed

16 files changed

+3102
-9
lines changed

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.

lua/copilot/SettingsOpts.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Enable: "enable",
2+
InlineSuggestEnable: "inlineSuggest.enable",
3+
ShowEditorCompletions: ["editor", "showEditorCompletions"],
4+
EnableAutoCompletions: ["editor", "enableAutoCompletions"],
5+
DelayCompletions: ["editor", "delayCompletions"],
6+
FilterCompletions: ["editor", "filterCompletions"],
7+
DisplayStyle: ["advanced", "displayStyle"],
8+
SecretKey: ["advanced", "secret_key"],
9+
SolutionLength: ["advanced", "length"],
10+
Stops: ["advanced", "stops"],
11+
Temperature: ["advanced", "temperature"],
12+
TopP: ["advanced", "top_p"],
13+
IndentationMode: ["advanced", "indentationMode"],
14+
InlineSuggestCount: ["advanced", "inlineSuggestCount"],
15+
ListCount: ["advanced", "listCount"],
16+
DebugOverrideProxyUrl: ["advanced", "debug.overrideProxyUrl"],
17+
DebugTestOverrideProxyUrl: ["advanced", "debug.testOverrideProxyUrl"],
18+
DebugEnableGitHubTelemetry: ["advanced", "debug.githubCTSIntegrationEnabled"],
19+
DebugOverrideEngine: ["advanced", "debug.overrideEngine"],
20+
DebugShowScores: ["advanced", "debug.showScores"],
21+
DebugOverrideLogLevels: ["advanced", "debug.overrideLogLevels"],
22+
DebugFilterLogCategories: ["advanced", "debug.filterLogCategories"],
23+
DebugUseSuffix: ["advanced", "debug.useSuffix"],
24+
DebugAcceptSelfSignedCertificate: ["advanced", "debug.acceptSelfSignedCertificate"]

lua/copilot/api.lua

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
local existing_matches = {}
2+
local util = require("copilot.util")
3+
local panel_printer = require("copilot.print_buf")
4+
local panel_results = {}
5+
6+
local api = {
7+
client_id = nil,
8+
client = nil,
9+
}
10+
api.set_client_info = function (client_id)
11+
api.client_id = client_id
12+
api.client = vim.lsp.get_client_by_id(client_id)
13+
return api.client_id ~= nil
14+
end
15+
16+
api.setup = function ()
17+
local id = util.find_copilot_client()
18+
api.set_client_info(id)
19+
end
20+
21+
local reply_callback = function ()
22+
end
23+
api.panel = {
24+
save = function (_, solution)
25+
if solution and type(solution) == "table" then
26+
panel_results[#panel_results+1] = solution
27+
end
28+
print(#solution)
29+
end,
30+
31+
open = function () require("copilot.panel").init() end,
32+
cmp = function ()
33+
end
34+
-- cmp = function (source, params, callback)
35+
-- if not client then return end
36+
-- local sent, req_id = client.rpc.request("getPanelCompletions", req_params, nil, reply_callback)
37+
-- vim.lsp.buf_request(0, "getPanelCompletions", req_params, function(_, response)
38+
-- -- local timer = vim.loop.new_timer()
39+
-- if response and not vim.tbl_isempty(panel_results) then
40+
-- for i, v in ipairs(panel_results) do
41+
-- print(i)
42+
-- print(v)
43+
-- end
44+
-- end
45+
-- end)
46+
-- end,
47+
48+
-- print = function (_, solutions)
49+
-- if type(solutions) == "table" then
50+
-- panel_printer.print(solutions)
51+
-- end
52+
-- end,
53+
-- timer:start(0, 100, vim.schedule_wrap(function()
54+
-- timer:stop()
55+
-- local entries = source:format_completions(params, panel_results)
56+
-- vim.schedule(function()
57+
-- print(entries)
58+
-- -- callback(entries)
59+
-- panel_results = {}
60+
-- end)
61+
-- end
62+
-- end))
63+
-- cmp = function (source, params, callback)
64+
-- local entries = {}
65+
-- if panel_results then
66+
-- entries = source:format_completions(params, panel_results)
67+
-- vim.schedule(function() callback(entries) end)
68+
-- panel_results = nil
69+
-- else
70+
-- callback({ isIncomplete = true })
71+
-- end
72+
-- end
73+
}
74+
75+
vim.api.nvim_create_user_command("CopilotPanel", function ()
76+
api.panel.open()
77+
end, {})
78+
79+
local function verify_existing (params)
80+
existing_matches[params.context.bufnr] = existing_matches[params.context.bufnr] or {}
81+
existing_matches[params.context.bufnr][params.context.cursor.row] = existing_matches[params.context.bufnr][params.context.cursor.row] or { IsIncomplete = true }
82+
local existing = existing_matches[params.context.bufnr][params.context.cursor.row]
83+
return existing
84+
end
85+
86+
api.complete_cycling = function (source, params, callback)
87+
local existing = verify_existing(params)
88+
local has_complete = false
89+
vim.lsp.buf_request(0, "getCompletionsCycling", util.get_completion_params(), function(_, response)
90+
if response and not vim.tbl_isempty(response.completions) then
91+
existing = vim.tbl_deep_extend("force", existing, source:format_completions(params, response.completions))
92+
has_complete = true
93+
end
94+
vim.schedule(function() callback(existing) end)
95+
end)
96+
if not has_complete then
97+
callback(existing)
98+
end
99+
end
100+
101+
return api

lua/copilot/copilot_handler.lua

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local M = { params = {} }
22
local util = require("copilot.util")
3+
local panel_handlers = require("copilot.api").panel
34

45
M.buf_attach_copilot = function()
56
if vim.tbl_contains(M.params.ft_disable, vim.bo.filetype) then return end
@@ -32,15 +33,26 @@ M.merge_server_opts = function (params)
3233
vim.schedule(M.buf_attach_copilot)
3334
vim.schedule(register_autocmd)
3435
end,
35-
on_attach = function()
36-
vim.schedule_wrap(params.on_attach())
37-
end,
36+
settings = {
37+
advanced = {
38+
listCount = 5, -- #completions for panel
39+
inlineSuggestCount = 1, -- #completions for getCompletions
40+
}
41+
},
42+
handlers = {
43+
["PanelSolution"] = panel_handlers.save,
44+
-- ["PanelSolutionsDone"] = function() end,
45+
}
3846
}, params.server_opts_overrides or {})
3947
end
4048

4149
M.start = function(params)
4250
M.params = params
43-
vim.lsp.start_client(M.merge_server_opts(params))
51+
local client_id = vim.lsp.start_client(M.merge_server_opts(params))
52+
if params.startup_function then
53+
-- params.startup_function()
54+
end
55+
return client_id
4456
end
4557

4658
return M

lua/copilot/dev/api.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
local copilot = {}
2+
local util = require("copilot.util")
3+
4+
5+
6+
function copilot:get_panel_solutions (params, callback, notify_reply_callback)
7+
local sent, id = self.client.rpc.request("getPanelCompletions", params, callback, notify_reply_callback)
8+
end
9+
10+
function copilot:request(method, callback, notify_reply_callback)
11+
local req_params = util.get_completion_params(method)
12+
end
13+
14+
copilot.new = function()
15+
16+
return copilot

lua/copilot/dev/copilot-cmp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/zach/.local/share/nvim/site/pack/packer/opt/copilot-cmp

lua/copilot/dev/init.lua

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
local fn = vim.fn
2+
local lsp = require("copilot.dev.lsp")
3+
local util = require("copilot.util")
4+
local bin = util.get_copilot_path(fn.stdpath("data") .. "/site/pack/packer")
5+
6+
local buf_attach_copilot = function()
7+
if not vim.bo.buflisted or not vim.bo.buftype == "" then return end
8+
local client_id = util.find_copilot_client()
9+
local buf_clients = vim.lsp.buf_get_clients(0)
10+
if not buf_clients and client_id or (client_id and not buf_clients[client_id]) then
11+
vim.lsp.buf_attach_client(0, client_id)
12+
end
13+
end
14+
15+
local attach_client = function ()
16+
local client_id = util.find_copilot_client()
17+
local buf_clients = vim.lsp.buf_get_clients(0)
18+
if not buf_clients and client_id or (client_id and not buf_clients[client_id]) then
19+
vim.lsp.buf_attach_client(0, client_id)
20+
end
21+
end
22+
23+
local client_id = vim.lsp.start_client({
24+
cmd = { "node", bin},
25+
name = "copilot",
26+
trace = "messages",
27+
root_dir = vim.loop.cwd(),
28+
autostart = true,
29+
on_init = function(_, _)
30+
vim.schedule(attach_client)
31+
end,
32+
on_attach = function()
33+
vim.schedule(attach_client)
34+
vim.schedule(function()
35+
require("copilot_cmp")._on_insert_enter()
36+
end)
37+
end,
38+
handlers = {
39+
}
40+
})
41+
42+
vim.api.nvim_create_autocmd({ "BufEnter" }, {
43+
callback = vim.schedule_wrap(buf_attach_copilot),
44+
})
45+
46+
return client_id

0 commit comments

Comments
 (0)