Skip to content

Commit 39ca323

Browse files
SPLYASHKAL3MON4D3
authored andcommitted
fix parser: use context extend from nodes.util
Replace local `context_extend` with `nodes.util.snippet_extend_context` Previously, when passing a string as the first argument (context), the parser ignored the 'extend' parameters. The local context_extend function did not merge extend fields if context was a string. Now, using node_util.snippet_extend_context ensures that extend parameters are correctly merged regardless of whether context is a string or a table.
1 parent f4ef0d0 commit 39ca323

1 file changed

Lines changed: 4 additions & 15 deletions

File tree

lua/luasnip/util/parser/init.lua

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local sNode = require("luasnip.nodes.snippet")
2+
local node_util = require("luasnip.nodes.util")
23
local ast_parser = require("luasnip.util.parser.ast_parser")
34
local parse = require("luasnip.util.parser.neovim_parser").parse
45
local Ast = require("luasnip.util.parser.neovim_ast")
@@ -65,23 +66,10 @@ function M.parse_snippet(context, body, opts)
6566

6667
return sNode.S(context, nodes)
6768
end
68-
local function context_extend(arg, extend)
69-
local argtype = type(arg)
70-
if argtype == "string" then
71-
arg = { trig = arg }
72-
end
73-
74-
if argtype == "table" then
75-
return vim.tbl_extend("keep", arg, extend or {})
76-
end
7769

78-
-- fall back to unchanged arg.
79-
-- log this, probably.
80-
return arg
81-
end
8270
extend_decorator.register(
8371
M.parse_snippet,
84-
{ arg_indx = 1, extend = context_extend },
72+
{ arg_indx = 1, extend = node_util.snippet_extend_context },
8573
{ arg_indx = 3 }
8674
)
8775

@@ -132,9 +120,10 @@ function M.parse_snipmate(context, body, opts)
132120
end
133121
return M.parse_snippet(context, body, opts)
134122
end
123+
135124
extend_decorator.register(
136125
M.parse_snipmate,
137-
{ arg_indx = 1, extend = context_extend },
126+
{ arg_indx = 1, extend = node_util.snippet_extend_context },
138127
{ arg_indx = 3 }
139128
)
140129

0 commit comments

Comments
 (0)