mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-07-10 17:34:34 +02:00
feat(snippets): try to use the snippet parse to get a preview
This commit is contained in:
parent
425dadef72
commit
eb0da3c92f
1 changed files with 9 additions and 4 deletions
|
@ -1,6 +1,8 @@
|
||||||
---@class lazyvim.util.cmp
|
---@class lazyvim.util.cmp
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
---@alias Placeholder {n:number, text:string}
|
||||||
|
|
||||||
---@param snippet string
|
---@param snippet string
|
||||||
---@param fn fun(placeholder:Placeholder):string
|
---@param fn fun(placeholder:Placeholder):string
|
||||||
---@return string
|
---@return string
|
||||||
|
@ -15,10 +17,13 @@ end
|
||||||
---@param snippet string
|
---@param snippet string
|
||||||
---@return string
|
---@return string
|
||||||
function M.snippet_preview(snippet)
|
function M.snippet_preview(snippet)
|
||||||
local ret = M.snippet_replace(snippet, function(placeholder)
|
local ok, parsed = pcall(function()
|
||||||
return M.snippet_preview(placeholder.text)
|
return vim.lsp._snippet_grammar.parse(snippet)
|
||||||
end):gsub("%$0", "")
|
end)
|
||||||
return ret
|
return ok and tostring(parsed)
|
||||||
|
or M.snippet_replace(snippet, function(placeholder)
|
||||||
|
return M.snippet_preview(placeholder.text)
|
||||||
|
end):gsub("%$0", "")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- This function replaces nested placeholders in a snippet with LSP placeholders.
|
-- This function replaces nested placeholders in a snippet with LSP placeholders.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue