|
1 | | -local existing_matches = {} |
2 | 1 | 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 |
33 | 11 | 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 | 12 | } |
74 | 13 |
|
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 | 14 | return api |
0 commit comments