Skip to content

Commit

Permalink
Format with stylua
Browse files Browse the repository at this point in the history
  • Loading branch information
L3MON4D3 committed Jun 24, 2023
1 parent cc88fc3 commit c7984d1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
6 changes: 5 additions & 1 deletion lua/luasnip/nodes/snippet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ local function init_snippet_context(context, opts)
-- otherwise, it is nil or string, if it is string, that is the name,
-- otherwise use "pattern" if regTrig is set, and finally fall back to
-- "plain" if it is not.
local engine_name = util.ternary(context.trigEngine ~= nil, context.trigEngine, util.ternary(context.regTrig ~= nil, "pattern", "plain"))
local engine_name = util.ternary(
context.trigEngine ~= nil,
context.trigEngine,
util.ternary(context.regTrig ~= nil, "pattern", "plain")
)
engine = trig_engines[engine_name]
end
effective_context.trig_matcher = engine(effective_context.trigger)
Expand Down
24 changes: 15 additions & 9 deletions lua/luasnip/nodes/util/trig_engines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ local jsregexp = require("luasnip.util.util").jsregexp

local function match_plain(line_to_cursor, trigger)
if
line_to_cursor:sub(
#line_to_cursor - #trigger + 1,
#line_to_cursor
) == trigger
line_to_cursor:sub(#line_to_cursor - #trigger + 1, #line_to_cursor)
== trigger
then
-- no captures for plain trigger.
return trigger, {}
Expand Down Expand Up @@ -53,14 +51,16 @@ if jsregexp then
local match = trig_compiled(line_to_cursor)[1]
if match then
-- return full match, and all groups.
return line_to_cursor:sub(match.begin_ind-1), match.groups
return line_to_cursor:sub(match.begin_ind - 1), match.groups
else
return nil
end
end
end
else
ecma_engine = function() return match_plain end
ecma_engine = function()
return match_plain
end
end

local function match_vim(line_to_cursor, trigger)
Expand All @@ -82,8 +82,14 @@ local function match_vim(line_to_cursor, trigger)
end

return {
plain = function() return match_plain end,
pattern = function() return match_pattern end,
plain = function()
return match_plain
end,
pattern = function()
return match_pattern
end,
ecma = ecma_engine,
vim = function() return match_vim end
vim = function()
return match_vim
end,
}
2 changes: 1 addition & 1 deletion lua/luasnip/util/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -643,5 +643,5 @@ return {
indx_of = indx_of,
lazy_table = lazy_table,
ternary = ternary,
jsregexp = jsregexp_ok and jsregexp
jsregexp = jsregexp_ok and jsregexp,
}
26 changes: 18 additions & 8 deletions tests/integration/snippet_basics_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1142,20 +1142,28 @@ describe("snippets_basic", function()
ecma = [[(\d+)]],
}
for engine, trig in pairs(engine_data) do
it("trigEngine \"" .. engine .. "\" works", function()
exec_lua([[
it('trigEngine "' .. engine .. '" works', function()
exec_lua(
[[
trigEngine, trig, body, doctrig = ...
snip = s({trig = trig, docTrig = "3", trigEngine = trigEngine}, {t"c1: ", l(l.CAPTURE1)})
ls.add_snippets("all", {snip})
]], engine, trig)
]],
engine,
trig
)
feed("i3")
exec_lua("ls.expand()")
screen:expect{grid=[[
screen:expect({
grid = [[
c1: 3^ |
{0:~ }|
{2:-- INSERT --} |]]}
{2:-- INSERT --} |]],
})
-- make sure docTrig works with all engines.
assert.is_true(exec_lua([[return snip:get_docstring()[1] == "c1: 3$0"]]))
assert.is_true(
exec_lua([[return snip:get_docstring()[1] == "c1: 3$0"]])
)
end)
end

Expand All @@ -1173,9 +1181,11 @@ describe("snippets_basic", function()
]])
feed("iasdf")
exec_lua([[ ls.expand() ]])
screen:expect{grid=[[
screen:expect({
grid = [[
aaaaa^ |
{0:~ }|
{2:-- INSERT --} |]]}
{2:-- INSERT --} |]],
})
end)
end)

0 comments on commit c7984d1

Please sign in to comment.