fix(snippet): always use top-level snippet session. Fixes #3199

This commit is contained in:
Folke Lemaitre 2024-05-26 18:51:11 +02:00
parent 59204df1cb
commit 53911748dd
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -86,6 +86,13 @@ function M.confirm(opts)
end
function M.expand(snippet)
-- Native sessions don't support nested snippet sessions.
-- Always use the top-level session.
-- Otherwise, when on the first placeholder and selecting a new completion,
-- the nested session will be used instead of the top-level session.
-- See: https://github.com/LazyVim/LazyVim/issues/3199
local session = vim.snippet.active() and vim.snippet._session or nil
local ok = pcall(vim.snippet.expand, snippet)
if not ok then
local fixed = M.snippet_fix(snippet)
@ -101,6 +108,11 @@ function M.expand(snippet)
{ title = "vim.snippet" }
)
end
-- Restore top-level session when needed
if session then
vim.snippet._session = session
end
end
return M