Skip to content

Commit

Permalink
Ensure repl autocompletion doesn't trigger in other buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed Aug 5, 2022
1 parent 4f63bda commit 66d33b7
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lua/dap/ext/autocompl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ local function destroy_timer()
end


local function trigger_completion()
local function trigger_completion(buf)
destroy_timer()
api.nvim_feedkeys(api.nvim_replace_termcodes('<C-x><C-o>', true, false, true), 'm', true)
if api.nvim_get_current_buf() == buf then
api.nvim_feedkeys(api.nvim_replace_termcodes('<C-x><C-o>', true, false, true), 'm', true)
end
end


Expand All @@ -25,6 +27,7 @@ function M._InsertCharPre()
if tonumber(vim.fn.pumvisible()) == 1 then
return
end
local buf = api.nvim_get_current_buf()
local char = api.nvim_get_vvar('char')
local session = require('dap').session()
local trigger_characters = ((session or {}).capabilities or {}).completionTriggerCharacters
Expand All @@ -36,7 +39,9 @@ function M._InsertCharPre()
end
if vim.tbl_contains(triggers, char) then
timer = vim.loop.new_timer()
timer:start(50, 0, vim.schedule_wrap(trigger_completion))
timer:start(50, 0, vim.schedule_wrap(function()
trigger_completion(buf)
end))
end
end

Expand All @@ -48,12 +53,15 @@ end

function M.attach(bufnr)
bufnr = bufnr or api.nvim_get_current_buf()
vim.cmd(string.format(
"autocmd InsertCharPre <buffer=%d> lua require('dap.ext.autocompl')._InsertCharPre()",
bufnr
))
vim.cmd(string.format(
"autocmd InsertLeave <buffer=%d> lua require('dap.ext.autocompl')._InsertLeave()",
vim.cmd(string.format([[
augroup dap_autocomplete-%d
au!
autocmd InsertCharPre <buffer=%d> lua require('dap.ext.autocompl')._InsertCharPre()
autocmd InsertLeave <buffer=%d> lua require('dap.ext.autocompl')._InsertLeave()
augroup end
]],
bufnr,
bufnr,
bufnr
))
end
Expand Down

0 comments on commit 66d33b7

Please sign in to comment.