Skip to content

Commit

Permalink
feat: reset whole luasnip cache on snippets added
Browse files Browse the repository at this point in the history
  • Loading branch information
Saghen committed Dec 20, 2024
1 parent b1b58e7 commit bff6c0f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lua/blink/cmp/sources/luasnip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit bff6c0f

Please sign in to comment.