Skip to content

Commit 66d33b7

Browse files
committed
Ensure repl autocompletion doesn't trigger in other buffers
1 parent 4f63bda commit 66d33b7

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

lua/dap/ext/autocompl.lua

+17-9
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ local function destroy_timer()
1212
end
1313

1414

15-
local function trigger_completion()
15+
local function trigger_completion(buf)
1616
destroy_timer()
17-
api.nvim_feedkeys(api.nvim_replace_termcodes('<C-x><C-o>', true, false, true), 'm', true)
17+
if api.nvim_get_current_buf() == buf then
18+
api.nvim_feedkeys(api.nvim_replace_termcodes('<C-x><C-o>', true, false, true), 'm', true)
19+
end
1820
end
1921

2022

@@ -25,6 +27,7 @@ function M._InsertCharPre()
2527
if tonumber(vim.fn.pumvisible()) == 1 then
2628
return
2729
end
30+
local buf = api.nvim_get_current_buf()
2831
local char = api.nvim_get_vvar('char')
2932
local session = require('dap').session()
3033
local trigger_characters = ((session or {}).capabilities or {}).completionTriggerCharacters
@@ -36,7 +39,9 @@ function M._InsertCharPre()
3639
end
3740
if vim.tbl_contains(triggers, char) then
3841
timer = vim.loop.new_timer()
39-
timer:start(50, 0, vim.schedule_wrap(trigger_completion))
42+
timer:start(50, 0, vim.schedule_wrap(function()
43+
trigger_completion(buf)
44+
end))
4045
end
4146
end
4247

@@ -48,12 +53,15 @@ end
4853

4954
function M.attach(bufnr)
5055
bufnr = bufnr or api.nvim_get_current_buf()
51-
vim.cmd(string.format(
52-
"autocmd InsertCharPre <buffer=%d> lua require('dap.ext.autocompl')._InsertCharPre()",
53-
bufnr
54-
))
55-
vim.cmd(string.format(
56-
"autocmd InsertLeave <buffer=%d> lua require('dap.ext.autocompl')._InsertLeave()",
56+
vim.cmd(string.format([[
57+
augroup dap_autocomplete-%d
58+
au!
59+
autocmd InsertCharPre <buffer=%d> lua require('dap.ext.autocompl')._InsertCharPre()
60+
autocmd InsertLeave <buffer=%d> lua require('dap.ext.autocompl')._InsertLeave()
61+
augroup end
62+
]],
63+
bufnr,
64+
bufnr,
5765
bufnr
5866
))
5967
end

0 commit comments

Comments
 (0)