Skip to content

Commit c331a58

Browse files
committed
almost there
1 parent 46bb2e7 commit c331a58

File tree

12 files changed

+80
-2941
lines changed

12 files changed

+80
-2941
lines changed

lua/copilot/api.lua

Lines changed: 9 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,14 @@
1-
local existing_matches = {}
21
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 ()
2+
local api = {}
3+
4+
api.panel = { --add print buf with highlighting needed
5+
create = function ()
6+
local client_id = util.find_copilot_client()
7+
local client = vim.lsp.get_client_by_id(client_id)
8+
return client_id and require("copilot.panel").init({
9+
client_id = client_id, client = client
10+
}) or false
3311
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
7312
}
7413

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-
10114
return api
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
local M = { params = {} }
22
local util = require("copilot.util")
3-
local panel_handlers = require("copilot.api").panel
43

54
M.buf_attach_copilot = function()
65
if vim.tbl_contains(M.params.ft_disable, vim.bo.filetype) then return end
@@ -18,7 +17,7 @@ local register_autocmd = function ()
1817
callback = vim.schedule_wrap(M.buf_attach_copilot),
1918
})
2019
else
21-
vim.cmd("au BufEnter * lua vim.schedule(function() require('copilot.copilot_handler').buf_attach_copilot() end)")
20+
vim.cmd("au BufEnter * lua vim.schedule(function() require('copilot.client').buf_attach_copilot() end)")
2221
end
2322
end
2423

@@ -33,26 +32,23 @@ M.merge_server_opts = function (params)
3332
vim.schedule(M.buf_attach_copilot)
3433
vim.schedule(register_autocmd)
3534
end,
35+
handlers = params.panel and {
36+
["PanelSolution"] = params.panel.save_completions,
37+
},
3638
settings = {
3739
advanced = {
38-
listCount = 5, -- #completions for panel
40+
listCount = 10, -- #completions for panel
3941
inlineSuggestCount = 1, -- #completions for getCompletions
4042
}
4143
},
42-
handlers = {
43-
["PanelSolution"] = panel_handlers.save,
44-
-- ["PanelSolutionsDone"] = function() end,
45-
}
4644
}, params.server_opts_overrides or {})
4745
end
4846

4947
M.start = function(params)
5048
M.params = params
5149
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
50+
local client = vim.lsp.get_client_by_id(client_id)
51+
return { client_id, client }
5652
end
5753

5854
return M

lua/copilot/dev/api.lua

Lines changed: 0 additions & 16 deletions
This file was deleted.

lua/copilot/dev/copilot-cmp

Lines changed: 0 additions & 1 deletion
This file was deleted.

lua/copilot/dev/init.lua

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)