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)
39
39
end
40
40
41
41
--- @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 ()
48
44
49
45
if lsp .initialization_failed () then
50
46
logger .error (" copilot-language-server failed to initialize" )
@@ -57,7 +53,7 @@ function M.buf_attach(force, bufnr)
57
53
return
58
54
end
59
55
60
- if not (force or util .should_attach (bufnr )) then
56
+ if not (force or util .should_attach ()) then
61
57
logger .debug (" not attaching to buffer based on force and should_attach criteria" )
62
58
return
63
59
end
@@ -167,11 +163,9 @@ function M.setup()
167
163
168
164
vim .api .nvim_create_autocmd (" FileType" , {
169
165
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 ),
175
169
})
176
170
177
171
vim .schedule (M .ensure_client_started )
Original file line number Diff line number Diff line change @@ -29,13 +29,13 @@ function M.version()
29
29
end )()
30
30
end
31
31
32
- --- @param opts ? { force ?: boolean , bufnr ?: integer }
32
+ --- @param opts ? { force ?: boolean }
33
33
function M .attach (opts )
34
34
logger .trace (" attaching to buffer" )
35
35
opts = opts or {}
36
36
37
37
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 ()
39
39
40
40
if not should_attach then
41
41
logger .notify (no_attach_reason .. " \n to force attach, run ':Copilot! attach'" )
@@ -45,7 +45,7 @@ function M.attach(opts)
45
45
opts .force = true
46
46
end
47
47
48
- c .buf_attach (opts .force , opts . bufnr )
48
+ c .buf_attach (opts .force )
49
49
end
50
50
51
51
function M .detach ()
Original file line number Diff line number Diff line change 34
34
35
35
--- @return boolean should_attach
36
36
--- @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 ()
47
38
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 )
49
40
50
41
if ft_disabled then
51
42
return not ft_disabled , ft_disabled_reason
52
43
end
53
44
45
+ local bufnr = vim .api .nvim_get_current_buf ()
54
46
local bufname = vim .api .nvim_buf_get_name (bufnr )
55
47
local conf_attach = config .should_attach (bufnr , bufname )
56
48
You can’t perform that action at this time.
0 commit comments