fix(snippets): fix snippets with multiple placeholders for the same tabstop

This commit is contained in:
Folke Lemaitre
2024-05-28 19:32:21 +02:00
parent eb0da3c92f
commit 1b86d7b2ad

View File

@ -28,10 +28,10 @@ end
-- This function replaces nested placeholders in a snippet with LSP placeholders.
function M.snippet_fix(snippet)
local nn = 0
local texts = {} ---@type table<number, string>
return M.snippet_replace(snippet, function(placeholder)
nn = nn + 1
return "${" .. nn .. ":" .. M.snippet_preview(placeholder.text) .. "}"
texts[placeholder.n] = texts[placeholder.n] or M.snippet_preview(placeholder.text)
return "${" .. placeholder.n .. ":" .. texts[placeholder.n] .. "}"
end)
end