1- local util = require (" copilot.util" )
21local M = { params = {} }
2+ local util = require (" copilot.util" )
33
44M .buf_attach_copilot = function ()
55 if vim .tbl_contains (M .params .ft_disable , vim .bo .filetype ) then return end
66 if not vim .bo .buflisted or not vim .bo .buftype == " " then return end
7- local client_id = require ( " copilot. util" ) .find_copilot_client ()
7+ local client_id = util .find_copilot_client ()
88 local buf_clients = vim .lsp .buf_get_clients (0 )
9- if client_id and buf_clients and not buf_clients [client_id ] then
9+ if not buf_clients and client_id or ( client_id and not buf_clients [client_id ]) then
1010 vim .lsp .buf_attach_client (0 , client_id )
1111 end
1212end
1313
14+ local register_autocmd = function ()
15+ if vim .fn .has (" nvim-0.7" ) > 0 then
16+ vim .api .nvim_create_autocmd ({ " BufEnter" }, {
17+ callback = vim .schedule_wrap (M .buf_attach_copilot ),
18+ })
19+ else
20+ vim .cmd (" au BufEnter * lua vim.schedule(function() require('copilot.copilot_handler').buf_attach_copilot() end)" )
21+ end
22+ end
23+
1424M .merge_server_opts = function (params )
1525 return vim .tbl_deep_extend (" force" , params .server_opts_overrides , {
1626 cmd = { require (" copilot.util" ).get_copilot_path (params .plugin_manager_path ) },
@@ -19,15 +29,8 @@ M.merge_server_opts = function (params)
1929 root_dir = vim .loop .cwd (),
2030 autostart = true ,
2131 on_init = function (_ , _ )
22- M .buf_attach_copilot ()
23- if vim .fn .has (" nvim-0.7" ) > 0 then
24- vim .api .nvim_create_autocmd ({ " BufEnter" }, {
25- callback = vim .schedule (function () M .buf_attach_copilot () end ),
26- once = false ,
27- })
28- else
29- vim .cmd (" au BufEnter * lua vim.schedule(function() require('copilot.copilot_handler').buf_attach_copilot() end)" )
30- end
32+ vim .schedule (M .buf_attach_copilot )
33+ vim .schedule (register_autocmd )
3134 end ,
3235 on_attach = function ()
3336 vim .schedule_wrap (params .on_attach ())
0 commit comments