Skip to content

Commit b625b32

Browse files
committed
update for working with cmp
1 parent 4ec316d commit b625b32

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

lua/copilot/copilot_handler.lua

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
local user_data = require('copilot.setup').get_cred()
22
local util = require('copilot.util')
33

4-
local function completion_handler(_, result, c, _)
5-
-- print(vim.inspect(result.completions))
6-
end
7-
8-
local get_completions = function()
9-
local params = util.get_completion_params()
10-
completions = vim.lsp.buf_request(0, 'getCompletions', params, completion_handler)
11-
end
124
local send_editor_info = function (a, b, c, d)
135
local responses = vim.lsp.buf_request_sync(0, 'setEditorInfo', {
146
editorPluginInfo = {
@@ -52,10 +44,5 @@ vim.lsp.start_client({
5244
end,
5345
on_attach = function()
5446
send_editor_info()
55-
vim.keymap.set('n', '<leader>i', get_completions, {noremap = true, silent = true})
56-
vim.api.nvim_create_autocmd({'TextChangedI'}, {
57-
callback = get_completions,
58-
once = false,
59-
})
6047
end
6148
})

lua/copilot/util.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,21 @@ M.get_copilot_path = function()
3737
end
3838
end
3939

40+
local function completion_handler (_, result, _, _)
41+
print(vim.inspect(result))
42+
end
43+
44+
M.register_completion_handler = function (handler)
45+
if handler then completion_handler = handler end
46+
end
47+
48+
M.send_completion_request = function()
49+
local params = M.get_completion_params()
50+
vim.lsp.buf_request(0, 'getCompletions', params, completion_handler)
51+
end
52+
53+
M.create_request_autocmd = function(group)
54+
vim.api.nvim_create_autocmd(group, {callback = M.send_completion_request})
55+
end
56+
4057
return M

0 commit comments

Comments
 (0)