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
e651c348e6
commit
2dca6130c0
8 changed files with 114 additions and 83 deletions
|
@ -132,13 +132,7 @@ function FunctionNode:set_dependents()
|
|||
self
|
||||
)
|
||||
elseif key_indexer.is_key(arg) then
|
||||
dict:set(
|
||||
vim.list_extend(
|
||||
{"key", arg.key},
|
||||
append_list
|
||||
),
|
||||
self
|
||||
)
|
||||
dict:set(vim.list_extend({ "key", arg.key }, append_list), self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ local M = {}
|
|||
|
||||
local key_mt = {}
|
||||
function M.new_key(key)
|
||||
return setmetatable({key = key}, key_mt)
|
||||
return setmetatable({ key = key }, key_mt)
|
||||
end
|
||||
|
||||
function M.is_key(t)
|
||||
|
|
|
@ -198,8 +198,9 @@ local function find_dependents(self, position_self, dict)
|
|||
)
|
||||
|
||||
if self.key then
|
||||
vim.list_extend(nodes,
|
||||
dict:find_all({"key", self.key, "dependents"}, "dependent") or {}
|
||||
vim.list_extend(
|
||||
nodes,
|
||||
dict:find_all({ "key", self.key, "dependents" }, "dependent") or {}
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -299,7 +300,11 @@ local function get_args(node, get_text_func_name)
|
|||
for _, arg in ipairs(node.args_absolute) do
|
||||
local argnode
|
||||
if key_indexer.is_key(arg) then
|
||||
argnode = node.parent.snippet.dependents_dict:get({"key", arg.key, "node"})
|
||||
argnode = node.parent.snippet.dependents_dict:get({
|
||||
"key",
|
||||
arg.key,
|
||||
"node",
|
||||
})
|
||||
else
|
||||
-- since arg may be a node, it may not be initialized in the snippet
|
||||
-- and therefore not have an absolute_insert_position. Check for that.
|
||||
|
@ -384,7 +389,7 @@ function Node:set_argnodes(dict)
|
|||
self.absolute_insert_position[#self.absolute_insert_position] = nil
|
||||
end
|
||||
if self.key then
|
||||
dict:set({"key", self.key, "node"}, self)
|
||||
dict:set({ "key", self.key, "node" }, self)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -271,7 +271,7 @@ local function _S(snip, nodes, opts)
|
|||
-- list to prevent its growing too large). No, the dependents are
|
||||
-- stored under their own absolute position (not absolute _insert_
|
||||
-- position, functionNodes don't have a jump-index, and thus can't
|
||||
-- be addressed using absolute insert position), which means that
|
||||
-- be addressed using absolute insert position), which means that
|
||||
--
|
||||
-- a) once a dependent is re-generated, for example by a
|
||||
-- dynamicNode, it will not take up new space, but simply overwrite
|
||||
|
@ -1280,7 +1280,7 @@ end
|
|||
|
||||
function Snippet:get_keyed_node(key)
|
||||
-- get key-node from dependents_dict.
|
||||
return self.dependents_dict:get({"key", key, "node"})
|
||||
return self.dependents_dict:get({ "key", key, "node" })
|
||||
end
|
||||
|
||||
return {
|
||||
|
|
|
@ -213,9 +213,10 @@ M.loaders = {
|
|||
}
|
||||
|
||||
function M.check_global_node_refs(test_name, resolve_map, fn)
|
||||
for _, index_strategy in ipairs({"absolute_indexer", "key_indexer"}) do
|
||||
for _, index_strategy in ipairs({ "absolute_indexer", "key_indexer" }) do
|
||||
getfenv(2).it(("%s (%s)."):format(test_name, index_strategy), function()
|
||||
exec_lua([[
|
||||
exec_lua(
|
||||
[[
|
||||
resolve_map, strategy = ...
|
||||
function _luasnip_test_resolve(key)
|
||||
if strategy == "absolute_indexer" then
|
||||
|
@ -224,7 +225,10 @@ function M.check_global_node_refs(test_name, resolve_map, fn)
|
|||
return k(resolve_map[key][2])
|
||||
end
|
||||
end
|
||||
]], resolve_map, index_strategy)
|
||||
]],
|
||||
resolve_map,
|
||||
index_strategy
|
||||
)
|
||||
fn()
|
||||
end)
|
||||
end
|
||||
|
|
|
@ -277,7 +277,7 @@ describe("DynamicNode", function()
|
|||
end)
|
||||
|
||||
ls_helpers.check_global_node_refs("nested fNode can depend on outside iNode", {
|
||||
first = {1, "i1"}
|
||||
first = { 1, "i1" },
|
||||
}, function()
|
||||
local snip = [[
|
||||
s("arg", {
|
||||
|
@ -291,25 +291,36 @@ describe("DynamicNode", function()
|
|||
end)
|
||||
})
|
||||
]]
|
||||
ls_helpers.static_docstring_test(snip, { "aaaaaa" }, { "${1:aaa}${2:aaa}$0" })
|
||||
ls_helpers.static_docstring_test(
|
||||
snip,
|
||||
{ "aaaaaa" },
|
||||
{ "${1:aaa}${2:aaa}$0" }
|
||||
)
|
||||
exec_lua("ls.snip_expand(" .. snip .. ")")
|
||||
screen:expect{grid=[[
|
||||
screen:expect({
|
||||
grid = [[
|
||||
^a{3:aa}aaa |
|
||||
{0:~ }|
|
||||
{2:-- SELECT --} |]]}
|
||||
{2:-- SELECT --} |]],
|
||||
})
|
||||
feed("some text")
|
||||
exec_lua("ls.active_update_dependents()")
|
||||
screen:expect{grid=[[
|
||||
screen:expect({
|
||||
grid = [[
|
||||
some text^some text |
|
||||
{0:~ }|
|
||||
{2:-- INSERT --} |]]}
|
||||
{2:-- INSERT --} |]],
|
||||
})
|
||||
feed("<Esc>cc")
|
||||
end)
|
||||
|
||||
ls_helpers.check_global_node_refs("generates correct static text when depending on node generated by dynamicNode", {
|
||||
first = {{1,0,1}, "in_dynode"}
|
||||
}, function()
|
||||
local snip = [[
|
||||
ls_helpers.check_global_node_refs(
|
||||
"generates correct static text when depending on node generated by dynamicNode",
|
||||
{
|
||||
first = { { 1, 0, 1 }, "in_dynode" },
|
||||
},
|
||||
function()
|
||||
local snip = [[
|
||||
s("trig", {
|
||||
-- arg will not be available when the static text is first queried.
|
||||
f(function(args) return args[1] end, _luasnip_test_resolve("first")),
|
||||
|
@ -317,12 +328,13 @@ describe("DynamicNode", function()
|
|||
return sn(nil, {i(1, "argnode-text", {key = "in_dynode"})})
|
||||
end, {})
|
||||
}) ]]
|
||||
ls_helpers.static_docstring_test(
|
||||
snip,
|
||||
{ "argnode-textargnode-text" },
|
||||
{ "argnode-text${1:${1:argnode-text}}$0" }
|
||||
)
|
||||
end)
|
||||
ls_helpers.static_docstring_test(
|
||||
snip,
|
||||
{ "argnode-textargnode-text" },
|
||||
{ "argnode-text${1:${1:argnode-text}}$0" }
|
||||
)
|
||||
end
|
||||
)
|
||||
|
||||
it(
|
||||
"generates correct static text when using environment variables.",
|
||||
|
|
|
@ -163,10 +163,13 @@ describe("FunctionNode", function()
|
|||
})
|
||||
end)
|
||||
|
||||
ls_helpers.check_global_node_refs("Updates after all argnodes become available.", {
|
||||
first = {{2,2}, "second_choice"}
|
||||
}, function()
|
||||
local snip = [[
|
||||
ls_helpers.check_global_node_refs(
|
||||
"Updates after all argnodes become available.",
|
||||
{
|
||||
first = { { 2, 2 }, "second_choice" },
|
||||
},
|
||||
function()
|
||||
local snip = [[
|
||||
s("trig", {
|
||||
i(1, "cccc"),
|
||||
t" ",
|
||||
|
@ -177,53 +180,54 @@ describe("FunctionNode", function()
|
|||
f(function(args) return args[1][1]..args[2][1] end, {_luasnip_test_resolve("first"), 1} )
|
||||
})
|
||||
]]
|
||||
assert.are.same(
|
||||
exec_lua("return " .. snip .. ":get_static_text()"),
|
||||
{ "cccc aaaa" }
|
||||
)
|
||||
-- the functionNode shouldn't be evaluated after expansion, the ai[2][2] isn't available.
|
||||
exec_lua("ls.snip_expand(" .. snip .. ")")
|
||||
screen:expect({
|
||||
grid = [[
|
||||
assert.are.same(
|
||||
exec_lua("return " .. snip .. ":get_static_text()"),
|
||||
{ "cccc aaaa" }
|
||||
)
|
||||
-- the functionNode shouldn't be evaluated after expansion, the ai[2][2] isn't available.
|
||||
exec_lua("ls.snip_expand(" .. snip .. ")")
|
||||
screen:expect({
|
||||
grid = [[
|
||||
^c{3:ccc} aaaa |
|
||||
{0:~ }|
|
||||
{2:-- SELECT --} |]],
|
||||
})
|
||||
})
|
||||
|
||||
-- change choice, the functionNode should now update.
|
||||
exec_lua("ls.jump(1)")
|
||||
exec_lua("ls.change_choice(1)")
|
||||
-- change choice, the functionNode should now update.
|
||||
exec_lua("ls.jump(1)")
|
||||
exec_lua("ls.change_choice(1)")
|
||||
|
||||
screen:expect({
|
||||
grid = [[
|
||||
screen:expect({
|
||||
grid = [[
|
||||
cccc ^b{3:bbb}bbbbcccc |
|
||||
{0:~ }|
|
||||
{2:-- SELECT --} |]],
|
||||
})
|
||||
})
|
||||
|
||||
-- change choice once more, so the necessary choice isn't visible, jump back,
|
||||
-- change text and update -> should lead to no new evaluation.
|
||||
exec_lua("ls.change_choice(1)")
|
||||
exec_lua("ls.jump(-1)")
|
||||
feed("aaaa")
|
||||
exec_lua("ls.active_update_dependents()")
|
||||
screen:expect({
|
||||
grid = [[
|
||||
-- change choice once more, so the necessary choice isn't visible, jump back,
|
||||
-- change text and update -> should lead to no new evaluation.
|
||||
exec_lua("ls.change_choice(1)")
|
||||
exec_lua("ls.jump(-1)")
|
||||
feed("aaaa")
|
||||
exec_lua("ls.active_update_dependents()")
|
||||
screen:expect({
|
||||
grid = [[
|
||||
aaaa^ aaaabbbbcccc |
|
||||
{0:~ }|
|
||||
{2:-- INSERT --} |]],
|
||||
})
|
||||
})
|
||||
|
||||
-- change choice once more, this time the fNode should be evaluated again.
|
||||
exec_lua("ls.jump(1)")
|
||||
exec_lua("ls.change_choice(1)")
|
||||
screen:expect({
|
||||
grid = [[
|
||||
-- change choice once more, this time the fNode should be evaluated again.
|
||||
exec_lua("ls.jump(1)")
|
||||
exec_lua("ls.change_choice(1)")
|
||||
screen:expect({
|
||||
grid = [[
|
||||
aaaa ^b{3:bbb}bbbbaaaa |
|
||||
{0:~ }|
|
||||
{2:-- SELECT --} |]],
|
||||
})
|
||||
end)
|
||||
})
|
||||
end
|
||||
)
|
||||
|
||||
it("Is correctly indented inside ISN.", function()
|
||||
local snip = [[
|
||||
|
@ -260,26 +264,34 @@ describe("FunctionNode", function()
|
|||
}))
|
||||
]])
|
||||
exec_lua("ls.jump(1) ls.change_choice(1)")
|
||||
screen:expect{grid=[[
|
||||
screen:expect({
|
||||
grid = [[
|
||||
asdf^asdfbbbb |
|
||||
{0:~ }|
|
||||
{2:-- INSERT --} |]]}
|
||||
{2:-- INSERT --} |]],
|
||||
})
|
||||
exec_lua("ls.jump(1) ls.change_choice(1)")
|
||||
screen:expect{grid=[[
|
||||
screen:expect({
|
||||
grid = [[
|
||||
asdfasdf^asdf |
|
||||
{0:~ }|
|
||||
{2:-- INSERT --} |]]}
|
||||
{2:-- INSERT --} |]],
|
||||
})
|
||||
exec_lua("ls.jump(-1) ls.change_choice(1) ls.jump(-1)")
|
||||
feed("1234")
|
||||
exec_lua("ls.jump(1)")
|
||||
screen:expect{grid=[[
|
||||
screen:expect({
|
||||
grid = [[
|
||||
1234^eeeeasdf |
|
||||
{0:~ }|
|
||||
{2:-- INSERT --} |]]}
|
||||
{2:-- INSERT --} |]],
|
||||
})
|
||||
exec_lua("ls.change_choice(1)")
|
||||
screen:expect{grid=[[
|
||||
screen:expect({
|
||||
grid = [[
|
||||
1234^12341234 |
|
||||
{0:~ }|
|
||||
{2:-- INSERT --} |]]}
|
||||
{2:-- INSERT --} |]],
|
||||
})
|
||||
end)
|
||||
end)
|
||||
|
|
|
@ -852,19 +852,23 @@ describe("snippets_basic", function()
|
|||
]])
|
||||
exec_lua("snip = ls.session.current_nodes[1].parent.snippet")
|
||||
assert.are.same(
|
||||
{"a"},
|
||||
exec_lua[[return snip:get_keyed_node("a"):get_text()]])
|
||||
{ "a" },
|
||||
exec_lua([[return snip:get_keyed_node("a"):get_text()]])
|
||||
)
|
||||
assert.are.same(
|
||||
{"b"},
|
||||
exec_lua[[return snip:get_keyed_node("b"):get_text()]])
|
||||
{ "b" },
|
||||
exec_lua([[return snip:get_keyed_node("b"):get_text()]])
|
||||
)
|
||||
assert.are.same(
|
||||
exec_lua([[return vim.NIL]]),
|
||||
exec_lua[[return snip:get_keyed_node("c")]])
|
||||
exec_lua([[return snip:get_keyed_node("c")]])
|
||||
)
|
||||
|
||||
exec_lua("ls.jump(1) ls.change_choice(1)")
|
||||
|
||||
assert.are.same(
|
||||
{"c"},
|
||||
exec_lua[[return snip:get_keyed_node("c"):get_text()]])
|
||||
{ "c" },
|
||||
exec_lua([[return snip:get_keyed_node("c"):get_text()]])
|
||||
)
|
||||
end)
|
||||
end)
|
||||
|
|
Loading…
Reference in a new issue