mirror of
https://github.com/L3MON4D3/LuaSnip
synced 2024-09-16 21:54:03 +02:00
Format with stylua
This commit is contained in:
parent
ff4339dc0c
commit
bc5ad405fc
7 changed files with 55 additions and 26 deletions
|
@ -11,7 +11,10 @@ local function set_choice_callback(_, indx)
|
|||
end
|
||||
|
||||
local function select_choice()
|
||||
assert(session.active_choice_nodes[vim.api.nvim_get_current_buf()], "No active choiceNode")
|
||||
assert(
|
||||
session.active_choice_nodes[vim.api.nvim_get_current_buf()],
|
||||
"No active choiceNode"
|
||||
)
|
||||
vim.ui.select(
|
||||
ls.get_current_choices(),
|
||||
{ kind = "luasnip" },
|
||||
|
|
|
@ -394,7 +394,8 @@ local function safe_choice_action(snip, ...)
|
|||
end
|
||||
end
|
||||
local function change_choice(val)
|
||||
local active_choice = session.active_choice_nodes[vim.api.nvim_get_current_buf()]
|
||||
local active_choice =
|
||||
session.active_choice_nodes[vim.api.nvim_get_current_buf()]
|
||||
assert(active_choice, "No active choiceNode")
|
||||
local new_active = util.no_region_check_wrap(
|
||||
safe_choice_action,
|
||||
|
@ -408,7 +409,8 @@ local function change_choice(val)
|
|||
end
|
||||
|
||||
local function set_choice(choice_indx)
|
||||
local active_choice = session.active_choice_nodes[vim.api.nvim_get_current_buf()]
|
||||
local active_choice =
|
||||
session.active_choice_nodes[vim.api.nvim_get_current_buf()]
|
||||
assert(active_choice, "No active choiceNode")
|
||||
local choice = active_choice.choices[choice_indx]
|
||||
assert(choice, "Invalid Choice")
|
||||
|
@ -424,7 +426,8 @@ local function set_choice(choice_indx)
|
|||
end
|
||||
|
||||
local function get_current_choices()
|
||||
local active_choice = session.active_choice_nodes[vim.api.nvim_get_current_buf()]
|
||||
local active_choice =
|
||||
session.active_choice_nodes[vim.api.nvim_get_current_buf()]
|
||||
assert(active_choice, "No active choiceNode")
|
||||
|
||||
local choice_lines = {}
|
||||
|
|
|
@ -141,7 +141,8 @@ function ChoiceNode:input_enter(_, dry_run)
|
|||
self.mark:update_opts(self.ext_opts.active)
|
||||
self:focus()
|
||||
|
||||
self.prev_choice_node = session.active_choice_nodes[vim.api.nvim_get_current_buf()]
|
||||
self.prev_choice_node =
|
||||
session.active_choice_nodes[vim.api.nvim_get_current_buf()]
|
||||
session.active_choice_nodes[vim.api.nvim_get_current_buf()] = self
|
||||
self.visited = true
|
||||
self.active = true
|
||||
|
@ -159,7 +160,8 @@ function ChoiceNode:input_leave(_, dry_run)
|
|||
|
||||
self.mark:update_opts(self:get_passive_ext_opts())
|
||||
self:update_dependents()
|
||||
session.active_choice_nodes[vim.api.nvim_get_current_buf()] = self.prev_choice_node
|
||||
session.active_choice_nodes[vim.api.nvim_get_current_buf()] =
|
||||
self.prev_choice_node
|
||||
self.active = false
|
||||
end
|
||||
|
||||
|
@ -341,7 +343,8 @@ function ChoiceNode:exit()
|
|||
end
|
||||
self.mark:clear()
|
||||
if self.active then
|
||||
session.active_choice_nodes[vim.api.nvim_get_current_buf()] = self.prev_choice_node
|
||||
session.active_choice_nodes[vim.api.nvim_get_current_buf()] =
|
||||
self.prev_choice_node
|
||||
end
|
||||
self.active = false
|
||||
end
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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, {}
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue