From 53911748ddc7f92793c6fec6348a9cde32159ef3 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sun, 26 May 2024 18:51:11 +0200 Subject: [PATCH] fix(snippet): always use top-level snippet session. Fixes #3199 --- lua/lazyvim/util/cmp.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lua/lazyvim/util/cmp.lua b/lua/lazyvim/util/cmp.lua index fd836d4e..957fb052 100644 --- a/lua/lazyvim/util/cmp.lua +++ b/lua/lazyvim/util/cmp.lua @@ -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