@@ -12,9 +12,11 @@ local function destroy_timer()
12
12
end
13
13
14
14
15
- local function trigger_completion ()
15
+ local function trigger_completion (buf )
16
16
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
18
20
end
19
21
20
22
@@ -25,6 +27,7 @@ function M._InsertCharPre()
25
27
if tonumber (vim .fn .pumvisible ()) == 1 then
26
28
return
27
29
end
30
+ local buf = api .nvim_get_current_buf ()
28
31
local char = api .nvim_get_vvar (' char' )
29
32
local session = require (' dap' ).session ()
30
33
local trigger_characters = ((session or {}).capabilities or {}).completionTriggerCharacters
@@ -36,7 +39,9 @@ function M._InsertCharPre()
36
39
end
37
40
if vim .tbl_contains (triggers , char ) then
38
41
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 ))
40
45
end
41
46
end
42
47
48
53
49
54
function M .attach (bufnr )
50
55
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 ,
57
65
bufnr
58
66
))
59
67
end
0 commit comments