Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

Commit 0b4c4fd

Browse files
author
iguanacucumber
committed
upstream: fix: Outdated completion item with mini.snippets
1 parent c462d74 commit 0b4c4fd

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

lua/cmp/init.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,12 @@ cmp.status = function()
328328
end
329329
end
330330

331+
---Ensures that cmp is the last receiver of the events specified.
332+
---@param events string[]
333+
cmp.resubscribe = function(events)
334+
autocmd.resubscribe(events)
335+
end
336+
331337
---@type cmp.Setup
332338
cmp.setup = setmetatable({
333339
global = function(c)

lua/cmp/utils/autocmd.lua

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ autocmd.group = vim.api.nvim_create_augroup('___cmp___', { clear = true })
66

77
autocmd.events = {}
88

9+
local function create_autocmd(event)
10+
vim.api.nvim_create_autocmd(event, {
11+
desc = ('nvim-cmp: autocmd: %s'):format(event),
12+
group = autocmd.group,
13+
callback = function()
14+
autocmd.emit(event)
15+
end,
16+
})
17+
end
18+
919
---Subscribe autocmd
1020
---@param events string|string[]
1121
---@param callback function
@@ -16,13 +26,7 @@ autocmd.subscribe = function(events, callback)
1626
for _, event in ipairs(events) do
1727
if not autocmd.events[event] then
1828
autocmd.events[event] = {}
19-
vim.api.nvim_create_autocmd(event, {
20-
desc = ('nvim-cmp: autocmd: %s'):format(event),
21-
group = autocmd.group,
22-
callback = function(details)
23-
autocmd.emit(event, details)
24-
end,
25-
})
29+
create_autocmd(event)
2630
end
2731
table.insert(autocmd.events[event], callback)
2832
end
@@ -50,4 +54,23 @@ autocmd.emit = function(event, details)
5054
end
5155
end
5256

57+
---Resubscribe to events
58+
---@param events string[]
59+
autocmd.resubscribe = function(events)
60+
-- Delete the autocommands if present
61+
local found = vim.api.nvim_get_autocmds({
62+
group = autocmd.group,
63+
event = events,
64+
})
65+
for _, to_delete in ipairs(found) do
66+
vim.api.nvim_del_autocmd(to_delete.id)
67+
end
68+
-- Recreate if event is known
69+
for _, event in ipairs(events) do
70+
if autocmd.events[event] then
71+
create_autocmd(event)
72+
end
73+
end
74+
end
75+
5376
return autocmd

0 commit comments

Comments
 (0)