@@ -12,9 +12,11 @@ local function destroy_timer()
1212end
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
1820end
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
4146end
4247
4853
4954function 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 ))
5967end
0 commit comments