File tree Expand file tree Collapse file tree 4 files changed +34
-1
lines changed Expand file tree Collapse file tree 4 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,10 @@ return {
31
31
root_dir = vim .uv .cwd (),
32
32
on_init = function (client )
33
33
local au = vim .api .nvim_create_augroup (" copilotlsp.init" , { clear = true })
34
+ local bufnr = vim .api .nvim_get_current_buf ()
35
+ if not require (" copilot-lsp.util" ).should_attach_to_buffer (bufnr ) then
36
+ return
37
+ end
34
38
-- NOTE: Inline Completions
35
39
-- TODO: We dont currently use this code path, so comment for now until a UI is built
36
40
-- vim.api.nvim_create_autocmd("TextChangedI", {
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ M.defaults = {
16
16
clear_on_large_distance = true ,
17
17
count_horizontal_moves = true ,
18
18
reset_on_approaching = true ,
19
+ buffer_blacklist = {},
19
20
},
20
21
}
21
22
Original file line number Diff line number Diff line change 28
28
--- Requests the NextEditSuggestion from the current cursor position
29
29
--- @param copilot_lss ? vim.lsp.Client | string
30
30
function M .request_nes (copilot_lss )
31
+ local bufnr = vim .api .nvim_get_current_buf ()
32
+ if not utils .should_attach_to_buffer (bufnr ) then
33
+ return
34
+ end
31
35
local pos_params = vim .lsp .util .make_position_params (0 , " utf-16" )
32
- local version = vim .lsp .util .buf_versions [vim . api . nvim_get_current_buf () ]
36
+ local version = vim .lsp .util .buf_versions [bufnr ]
33
37
if type (copilot_lss ) == " string" then
34
38
copilot_lss = vim .lsp .get_clients ({ name = copilot_lss })[1 ]
35
39
end
Original file line number Diff line number Diff line change 1
1
local M = {}
2
+ local config = require (" copilot-lsp.config" ).config
3
+ local api = vim .api
4
+
2
5
--- @param edit copilotlsp.InlineEdit
3
6
function M .apply_inline_edit (edit )
4
7
local bufnr = vim .uri_to_bufnr (edit .textDocument .uri )
@@ -7,6 +10,27 @@ function M.apply_inline_edit(edit)
7
10
vim .lsp .util .apply_text_edits ({ edit }, bufnr , " utf-16" )
8
11
end
9
12
13
+ --- Checks if Copilot should attach to a buffer
14
+ --- @param bufnr integer
15
+ --- @return boolean
16
+ function M .should_attach_to_buffer (bufnr )
17
+ if
18
+ not vim .fn .getbufvar (bufnr , " &buflisted" ) == 1
19
+ or vim .bo [bufnr ].buftype ~= " "
20
+ or not api .nvim_buf_is_valid (bufnr )
21
+ or not api .nvim_buf_is_loaded (bufnr )
22
+ then
23
+ return false
24
+ end
25
+ local name = api .nvim_buf_get_name (bufnr )
26
+ for _ , b_name in ipairs (config .nes .buffer_blacklist or {}) do
27
+ if name :match (b_name ) then
28
+ return false
29
+ end
30
+ end
31
+ return true
32
+ end
33
+
10
34
--- Debounces calls to a function, and ensures it only runs once per delay
11
35
--- even if called repeatedly.
12
36
--- @param fn fun ( ... : any )
You can’t perform that action at this time.
0 commit comments