File tree Expand file tree Collapse file tree 3 files changed +12
-26
lines changed
Expand file tree Collapse file tree 3 files changed +12
-26
lines changed Original file line number Diff line number Diff line change @@ -39,12 +39,8 @@ function M.buf_is_attached(bufnr)
3939end
4040
4141--- @param force ? boolean
42- --- @param bufnr ? integer The buffer number of which will be attached. 0 or nil for current buffer
43- function M .buf_attach (force , bufnr )
44- bufnr = bufnr or vim .api .nvim_get_current_buf ()
45- if bufnr == 0 then
46- bufnr = vim .api .nvim_get_current_buf ()
47- end
42+ function M .buf_attach (force )
43+ local bufnr = vim .api .nvim_get_current_buf ()
4844
4945 if lsp .initialization_failed () then
5046 logger .error (" copilot-language-server failed to initialize" )
@@ -57,7 +53,7 @@ function M.buf_attach(force, bufnr)
5753 return
5854 end
5955
60- if not (force or util .should_attach (bufnr )) then
56+ if not (force or util .should_attach ()) then
6157 logger .debug (" not attaching to buffer based on force and should_attach criteria" )
6258 return
6359 end
@@ -167,11 +163,9 @@ function M.setup()
167163
168164 vim .api .nvim_create_autocmd (" FileType" , {
169165 group = M .augroup ,
170- callback = function (ev )
171- vim .schedule (function ()
172- M .buf_attach (nil , ev .buf )
173- end )
174- end ,
166+ callback = vim .schedule_wrap (function ()
167+ M .buf_attach ()
168+ end ),
175169 })
176170
177171 vim .schedule (M .ensure_client_started )
Original file line number Diff line number Diff line change @@ -29,13 +29,13 @@ function M.version()
2929 end )()
3030end
3131
32- --- @param opts ? { force ?: boolean , bufnr ?: integer }
32+ --- @param opts ? { force ?: boolean }
3333function M .attach (opts )
3434 logger .trace (" attaching to buffer" )
3535 opts = opts or {}
3636
3737 if not opts .force then
38- local should_attach , no_attach_reason = u .should_attach (opts . bufnr )
38+ local should_attach , no_attach_reason = u .should_attach ()
3939
4040 if not should_attach then
4141 logger .notify (no_attach_reason .. " \n to force attach, run ':Copilot! attach'" )
@@ -45,7 +45,7 @@ function M.attach(opts)
4545 opts .force = true
4646 end
4747
48- c .buf_attach (opts .force , opts . bufnr )
48+ c .buf_attach (opts .force )
4949end
5050
5151function M .detach ()
Original file line number Diff line number Diff line change 3434
3535--- @return boolean should_attach
3636--- @return string ? no_attach_reason
37- function M .should_attach (bufnr )
38- bufnr = bufnr or vim .api .nvim_get_current_buf ()
39- if bufnr == 0 then
40- bufnr = vim .api .nvim_get_current_buf ()
41- end
42-
43- if not vim .api .nvim_buf_is_valid (bufnr ) then
44- return false , " Invalid buffer"
45- end
46-
37+ function M .should_attach ()
4738 local ft = config .filetypes
48- local ft_disabled , ft_disabled_reason = require (" copilot.client.filetypes" ).is_ft_disabled (vim .bo [ bufnr ] .filetype , ft )
39+ local ft_disabled , ft_disabled_reason = require (" copilot.client.filetypes" ).is_ft_disabled (vim .bo .filetype , ft )
4940
5041 if ft_disabled then
5142 return not ft_disabled , ft_disabled_reason
5243 end
5344
45+ local bufnr = vim .api .nvim_get_current_buf ()
5446 local bufname = vim .api .nvim_buf_get_name (bufnr )
5547 local conf_attach = config .should_attach (bufnr , bufname )
5648
You can’t perform that action at this time.
0 commit comments