Skip to content

Commit 3d5f445

Browse files
committed
fix(cond): correct behavior of specifying conditions
1 parent 707cde0 commit 3d5f445

1 file changed

Lines changed: 11 additions & 15 deletions

File tree

lua/luasnippy.lua

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ local fmt = require("luasnip.extras.fmt").fmt
33
local conditions = require("luasnip.extras.conditions")
44
local conditionsExpand = require("luasnip.extras.conditions.expand")
55

6+
local luasnippy = {}
7+
68
---@return fun(_, parent): any # a function that extracts the capture with the given index from the parent snippet, for use in function node.
7-
local function capture_extract(indice)
9+
function luasnippy.capture_extract(indice)
810
return function (_, parent)
911
return parent.snippet.captures[indice]
1012
end
@@ -29,12 +31,12 @@ local function parse_context(context, baseset)
2931
end
3032
if context:match("b") then
3133
context_tbl.condition = context_tbl.condition
32-
and context_tbl.condition + conditionsExpand.line_begin
34+
and context_tbl.condition * conditionsExpand.line_begin
3335
or conditionsExpand.line_begin
3436
end
3537
if context:match("Ce") then
3638
context_tbl.condition = context_tbl.condition
37-
and context_tbl.condition + conditionsExpand.line_end
39+
and context_tbl.condition * conditionsExpand.line_end
3840
or conditionsExpand.line_end
3941
end
4042

@@ -66,7 +68,7 @@ end
6668
---@param body_elems any|nil The body elements of the snippet, as in `fmt` (see `nodes` in `:h luasnip-extras-fmt`)
6769
---@param opts table|nil Passed to `fmt` as the third argument (see `opts` in `:h luasnip-extras-fmt`)
6870
---@return SnippetTuple # The snippet tuple with the given context, trigger, and body elements
69-
local function snippy(context, trigger, body_str, body_elems, opts)
71+
function luasnippy.snippy(context, trigger, body_str, body_elems, opts)
7072
local context_tbl
7173
if type(context) == "table" then
7274
if context[1] then
@@ -83,15 +85,15 @@ local function snippy(context, trigger, body_str, body_elems, opts)
8385
end
8486

8587
---Works the same way as `snippy`, with delimiters set to angular brackets "<>". It to `snippy` is what `fmta` to `fmt`, see `:h luasnip-extras-fmt`.
86-
local function snippy_angular(context, trigger, body_str, body_elems, opts)
88+
function luasnippy.snippy_angular(context, trigger, body_str, body_elems, opts)
8789
opts = opts or {}; opts.delimiters = "<>"
88-
return snippy(context, trigger, body_str, body_elems, opts)
90+
return luasnippy.snippy(context, trigger, body_str, body_elems, opts)
8991
end
9092

9193
---@param cond table|function A function, or a condition object (see `CONDITION OBJECTS` in `:h luasnip-extras-conditions`).
9294
---@param snippets (SnippetTuple|SnippetTuple[])[]
9395
---@return SnippetTuple[] # The snippets that respects the condition
94-
local function conditional_by(cond, snippets)
96+
function luasnippy.conditional_by(cond, snippets)
9597
if type(cond) == "function" then
9698
cond = conditions.make_condition(cond)
9799
elseif type(cond) ~= "table" then
@@ -115,7 +117,7 @@ end
115117
---Accepts a list of LuaSnippy snippets and converts them to LuaSnip snippets, for use in snippet file `return` (see `:h luasnip-loaders-lua`) or `luasnip.add_snippets` (see `:h luasnip-api`).
116118
---@param snippetTuples (SnippetTuple|SnippetTuple[])[]
117119
---@return any # list of LuaSnip snippets
118-
local function pack_snippets(snippetTuples)
120+
function luasnippy.pack_snippets(snippetTuples)
119121
local snippets = {}
120122
for _, snipgrp in ipairs(snippetTuples) do
121123
if snipgrp._snip then
@@ -130,10 +132,4 @@ local function pack_snippets(snippetTuples)
130132
return snippets
131133
end
132134

133-
return {
134-
snippy = snippy,
135-
snippy_angular = snippy_angular,
136-
conditional_by = conditional_by,
137-
capture_extract = capture_extract,
138-
pack_snippets = pack_snippets,
139-
}
135+
return luasnippy

0 commit comments

Comments
 (0)