fix(snippet): Double $ in snippet template
Closes #207 Due to $ being automatically interpreted as snippet variables, we need to double the $ in the template to let it pass when generating the snippet. Solves issues with php parameters that have their $ deleted when using snippets.
This commit is contained in:
@@ -48,6 +48,13 @@ snippet.engines = {}
|
|||||||
---@private
|
---@private
|
||||||
snippet.to_snippet = function(template, marks, pos)
|
snippet.to_snippet = function(template, marks, pos)
|
||||||
local offset, ph = {}, {}
|
local offset, ph = {}, {}
|
||||||
|
|
||||||
|
-- Add double $ for template before creating the snippet so that text with $ (such as parameters in php)
|
||||||
|
-- are not interpreted as snippet
|
||||||
|
for i, str in ipairs(template) do
|
||||||
|
template[i] = str:gsub("%$", "$$") -- Escape $
|
||||||
|
end
|
||||||
|
|
||||||
for i, m in ipairs(marks) do
|
for i, m in ipairs(marks) do
|
||||||
local r, col = m.row - pos[1] + 1, m.col
|
local r, col = m.row - pos[1] + 1, m.col
|
||||||
ph[i] = (m.text and conf.enable_placeholders) and string.format("${%d:%s}", i, m.text) or "$" .. i
|
ph[i] = (m.text and conf.enable_placeholders) and string.format("${%d:%s}", i, m.text) or "$" .. i
|
||||||
@@ -81,6 +88,8 @@ snippet.engines.luasnip = function(snip, pos)
|
|||||||
-- Convert the snippet to string
|
-- Convert the snippet to string
|
||||||
local _snip = table.concat(snip, "\n")
|
local _snip = table.concat(snip, "\n")
|
||||||
|
|
||||||
|
vim.print(snip)
|
||||||
|
|
||||||
ls.snip_expand(
|
ls.snip_expand(
|
||||||
|
|
||||||
ls.s("", ls.parser.parse_snippet(nil, _snip, { trim_empty = false, dedent = false }), {
|
ls.s("", ls.parser.parse_snippet(nil, _snip, { trim_empty = false, dedent = false }), {
|
||||||
|
|||||||
Reference in New Issue
Block a user