Skip to content

Commit ee0e551

Browse files
committed
feat: update api for latest version
1 parent 427faff commit ee0e551

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

lua/copilot/api.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,23 @@ function mod.notify(client, method, params)
2828
return client.notify(method, params)
2929
end
3030

31-
---@alias copilot_set_editor_info_params { editorInfo: { name: string, version: string }, editorPluginInfo: { name: string, version: string } }
31+
---@alias copilot_editor_info { name: string, version: string }
32+
---@alias copilot_editor_plugin_info { name: string, version: string }
33+
---@alias copilot_set_editor_info_params { editorInfo: copilot_editor_info, editorPluginInfo: copilot_editor_plugin_info, editorConfiguration: copilot_editor_configuration }
3234

3335
---@param params copilot_set_editor_info_params
3436
function mod.set_editor_info(client, params)
3537
return mod.notify(client, "setEditorInfo", params)
3638
end
3739

40+
---@alias copilot_editor_configuration { enableAutoCompletions: boolean, disabledLanguages: string[] }
41+
---@alias copilot_notify_change_configuration_params { settings: copilot_editor_configuration }
42+
43+
---@param params copilot_notify_change_configuration_params
44+
function mod.notify_change_configuration(client, params)
45+
return mod.notify(client, "notifyChangeConfiguration", params)
46+
end
47+
3848
---@alias copilot_check_status_params { options?: { localChecksOnly?: boolean } }
3949
---@alias copilot_check_status_data { user?: string }
4050

lua/copilot/client.lua

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,18 @@ M.merge_server_opts = function (params)
4747
autostart = true,
4848
single_file_support = true,
4949
on_init = function(client)
50-
api.set_editor_info(client, util.get_editor_info())
50+
---@type copilot_set_editor_info_params
51+
local set_editor_info_params = util.get_editor_info()
52+
set_editor_info_params.editorConfiguration = util.get_editor_configuration()
53+
api.set_editor_info(client, set_editor_info_params)
5154
vim.schedule(M.buf_attach_copilot)
5255
vim.schedule(register_autocmd)
5356
end,
5457
handlers = {
5558
PanelSolution = api.handlers.PanelSolution,
5659
PanelSolutionsDone = api.handlers.PanelSolutionsDone,
5760
statusNotification = api.handlers.statusNotification,
58-
}
61+
},
5962
}, params.server_opts_overrides or {})
6063
end
6164

lua/copilot/util.lua

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function M.get_next_id()
66
return id
77
end
88

9-
---@return copilot_set_editor_info_params
9+
---@return { editorInfo: copilot_editor_info, editorPluginInfo: copilot_editor_plugin_info }
1010
function M.get_editor_info()
1111
local info = {
1212
editorInfo = {
@@ -15,7 +15,7 @@ function M.get_editor_info()
1515
},
1616
editorPluginInfo = {
1717
name = "copilot.vim",
18-
version = '1.5.3',
18+
version = '1.6.0',
1919
},
2020
}
2121
return info
@@ -207,6 +207,28 @@ M.get_completion_params = function(opts)
207207
return M.get_doc_params(opts)
208208
end
209209

210+
211+
---@return copilot_editor_configuration
212+
function M.get_editor_configuration()
213+
local c = require("copilot.client")
214+
215+
local filetypes = vim.deepcopy(c.params.filetypes)
216+
if filetypes['*'] == nil then
217+
filetypes = vim.tbl_deep_extend('keep', filetypes, internal_filetypes)
218+
end
219+
220+
---@type string[]
221+
local disabled_filetypes = vim.tbl_filter(function(ft)
222+
return filetypes[ft] == false
223+
end, vim.tbl_keys(filetypes))
224+
table.sort(disabled_filetypes)
225+
226+
return {
227+
enableAutoCompletions = not not (c.params.panel.enabled or c.params.suggestion.enabled),
228+
disabledLanguages = disabled_filetypes,
229+
}
230+
end
231+
210232
M.get_copilot_path = function(plugin_path)
211233
for _, loc in ipairs({ "/opt", "/start", "" }) do
212234
local copilot_path = plugin_path .. loc .. "/copilot.lua/copilot/index.js"

0 commit comments

Comments
 (0)