Skip to content

fix parser: use context extend from nodes.util#1403

Merged
L3MON4D3 merged 1 commit into
L3MON4D3:masterfrom
SPLYASHKA:fix/parser-extend-bug
Jan 18, 2026
Merged

fix parser: use context extend from nodes.util#1403
L3MON4D3 merged 1 commit into
L3MON4D3:masterfrom
SPLYASHKA:fix/parser-extend-bug

Conversation

@SPLYASHKA
Copy link
Copy Markdown
Contributor

Replace local context_extend with nodes.util.snippet_extend_context

The default extend behavior was inconsistent between the functions (ls.snippet and ls.parser.parse_snippet / ls.parser.parse_snipmate)

Previously, when passing a string as the first argument (context), the parser ignored the 'extend' parameters (while ls.snippet not). The local context_extend function did not merge extend fields if context was a string. Now, using nodes.util.snippet_extend_context ensures that extend parameters are correctly merged regardless of whether context is a string or a table.

@SPLYASHKA
Copy link
Copy Markdown
Contributor Author

For example (before changes)

local s_mathonly = ls.extend_decorator.apply(s, {}, { condition = tex.math_mode })
local s_mathonlyy = ls.extend_decorator.apply(s, { condition = tex.math_mode })
local parse_mathonly = ls.extend_decorator.apply(parse, { condition = tex.math_mode })
local math_auto = {
}

local greek = {
  parse_mathonly({ trig = "@a" }, "\\alpha"),
  parse_mathonly("@h", "\\alpha"),
  s_mathonly("@g", t("\\gamma")),
  s_mathonlyy("@u", t("\\gamma")),
}
vim.list_extend(math_auto, greek)

return {}, vim.list_extend(text_auto, math_auto)

s_mathonly, s_mathonlyy work perfectly fine, while parse_mathonly use condition = tex.math_mode only if you pass context as table.
("@A","@g","@U" - autosnippets with condition, "@h" - autosnippet without condition)

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.
@L3MON4D3 L3MON4D3 force-pushed the fix/parser-extend-bug branch from a2ddf31 to 07978a7 Compare January 18, 2026 22:24
@L3MON4D3
Copy link
Copy Markdown
Owner

Hey, sorry for the (very) late reply :/

This looks like something that I should've done in the first place, Thank You!

@L3MON4D3 L3MON4D3 merged commit 39ca323 into L3MON4D3:master Jan 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants