@@ -174,14 +174,12 @@ function M.use_client(callback)
174174end
175175
176176--- @param bufnr integer
177- local function on_filetype (bufnr )
178- logger .trace (" filetype autocmd called" )
177+ local function on_buf_enter (bufnr )
178+ logger .trace (" on_buf_enter autocmd called" )
179179 vim .schedule (function ()
180180 if not vim .api .nvim_buf_is_valid (bufnr ) then
181181 return
182182 end
183- -- todo: when we do lazy/late attaching this needs changing
184-
185183 -- This is to handle the case where the filetype changes after the buffer is already attached,
186184 -- causing the LSP to raise an error
187185 local previous_ft = util .get_buffer_previous_ft (bufnr )
@@ -217,20 +215,20 @@ function M.setup()
217215 vim .api .nvim_create_augroup (augroup , { clear = true })
218216 M .augroup = augroup
219217
220- vim .api .nvim_create_autocmd (" FileType " , {
218+ vim .api .nvim_create_autocmd (" BufEnter " , {
221219 group = M .augroup ,
222220 callback = function (args )
223221 local bufnr = (args and args .buf ) or nil
224- on_filetype (bufnr )
222+ on_buf_enter (bufnr )
225223 end ,
226- desc = " [copilot] (suggestion) file type " ,
224+ desc = " [copilot] (client) buf entered " ,
227225 })
228226
229227 vim .schedule (M .ensure_client_started )
230- -- FileType is likely already triggered for shown buffer, so we trigger it manually
228+ -- BufEnter is likely already triggered for shown buffer, so we trigger it manually
231229 local bufnr = vim .api .nvim_get_current_buf ()
232230 vim .schedule (function ()
233- M . buf_attach ( false , bufnr )
231+ on_buf_enter ( bufnr )
234232 end )
235233end
236234
0 commit comments