diff --git a/lua/blink/cmp/sources/luasnip.lua b/lua/blink/cmp/sources/luasnip.lua index 95f64c85..b0dfe53c 100644 --- a/lua/blink/cmp/sources/luasnip.lua +++ b/lua/blink/cmp/sources/luasnip.lua @@ -21,27 +21,25 @@ function source.new(opts) use_show_condition = { config.use_show_condition, 'boolean' }, show_autosnippets = { config.show_autosnippets, 'boolean' }, }) + local self = setmetatable({}, { __index = source }) self.config = config self.items_cache = {} + local luasnip_ag = vim.api.nvim_create_augroup('BlinkCmpLuaSnipReload', { clear = true }) vim.api.nvim_create_autocmd('User', { pattern = 'LuasnipSnippetsAdded', - callback = function() - local ok, _ = pcall(require, 'luasnip.session') - if not ok then return end - local ft = require('luasnip.session').latest_load_ft - self.items_cache[ft] = nil - end, + callback = function() self:reload() end, group = luasnip_ag, desc = 'Reset internal cache of luasnip source of blink.cmp when new snippets are added', }) vim.api.nvim_create_autocmd('User', { pattern = 'LuasnipCleanup', - callback = function() require('blink.cmp').reload('luasnip') end, + callback = function() self:reload() end, group = luasnip_ag, desc = 'Reload luasnip source of blink.cmp when snippets are cleared', }) + return self end