Skip to content

Conversation

@SPLYASHKA
Copy link

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 and others added 2 commits November 25, 2025 16:03
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.
@SPLYASHKA
Copy link
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)

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.

1 participant