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
77d02781c7
commit
d94c4893e6
9 changed files with 45 additions and 27 deletions
|
@ -155,7 +155,8 @@ local function store_cursor_node_relative(node)
|
|||
|
||||
store_id = store_id + 1
|
||||
|
||||
snip_data.cursor_end_relative = util.pos_sub(util.get_cursor_0ind(), node.mark:get_endpoint(1))
|
||||
snip_data.cursor_end_relative =
|
||||
util.pos_sub(util.get_cursor_0ind(), node.mark:get_endpoint(1))
|
||||
|
||||
data[snip] = snip_data
|
||||
|
||||
|
@ -167,16 +168,14 @@ end
|
|||
|
||||
local function get_corresponding_node(parent, data)
|
||||
return parent:find_node(function(test_node)
|
||||
return (test_node.store_id == data.store_id) or (data.key ~= nil and test_node.key == data.key)
|
||||
return (test_node.store_id == data.store_id)
|
||||
or (data.key ~= nil and test_node.key == data.key)
|
||||
end)
|
||||
end
|
||||
|
||||
local function restore_cursor_pos_relative(node, data)
|
||||
util.set_cursor_0ind(
|
||||
util.pos_add(
|
||||
node.mark:get_endpoint(1),
|
||||
data.cursor_end_relative
|
||||
)
|
||||
util.pos_add(node.mark:get_endpoint(1), data.cursor_end_relative)
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -184,7 +183,8 @@ local function node_update_dependents_preserve_position(node, opts)
|
|||
local restore_data = store_cursor_node_relative(node)
|
||||
|
||||
-- update all nodes that depend on this one.
|
||||
local ok, res = pcall(node.update_dependents, node, {own=true, parents=true})
|
||||
local ok, res =
|
||||
pcall(node.update_dependents, node, { own = true, parents = true })
|
||||
if not ok then
|
||||
local snip = node:get_snippet()
|
||||
|
||||
|
@ -194,7 +194,10 @@ local function node_update_dependents_preserve_position(node, opts)
|
|||
snip.trigger,
|
||||
res
|
||||
)
|
||||
return { jump_done = false, new_node = session.current_nodes[vim.api.nvim_get_current_buf()] }
|
||||
return {
|
||||
jump_done = false,
|
||||
new_node = session.current_nodes[vim.api.nvim_get_current_buf()],
|
||||
}
|
||||
end
|
||||
|
||||
-- update successful => check if the current node is still visible.
|
||||
|
@ -228,11 +231,17 @@ local function node_update_dependents_preserve_position(node, opts)
|
|||
-- since the node was no longer visible after an update, it must have
|
||||
-- been contained in a dynamicNode, and we don't have to handle the
|
||||
-- case that we can't find it.
|
||||
while node_parent.dynamicNode == nil or node_parent.dynamicNode.visible == false do
|
||||
while
|
||||
node_parent.dynamicNode == nil
|
||||
or node_parent.dynamicNode.visible == false
|
||||
do
|
||||
node_parent = node_parent.parent
|
||||
end
|
||||
local d = node_parent.dynamicNode
|
||||
assert(d.active, "Visible dynamicNode that was a parent of the current node is not active after the update!! If you get this message, please open an issue with LuaSnip!")
|
||||
assert(
|
||||
d.active,
|
||||
"Visible dynamicNode that was a parent of the current node is not active after the update!! If you get this message, please open an issue with LuaSnip!"
|
||||
)
|
||||
|
||||
local new_node = get_corresponding_node(d, snip_restore_data)
|
||||
|
||||
|
@ -248,7 +257,10 @@ local function node_update_dependents_preserve_position(node, opts)
|
|||
else
|
||||
-- could not find corresponding node -> just jump into the
|
||||
-- dynamicNode that should have generated it.
|
||||
return { jump_done = true, new_node = d:jump_into_snippet(opts.no_move) }
|
||||
return {
|
||||
jump_done = true,
|
||||
new_node = d:jump_into_snippet(opts.no_move),
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -258,7 +270,10 @@ local function active_update_dependents()
|
|||
-- don't update if a jump/change_choice is in progress, or if we don't have
|
||||
-- an active node.
|
||||
if not session.jump_active and active ~= nil then
|
||||
local upd_res = node_update_dependents_preserve_position(active, { no_move = false, restore_position = true })
|
||||
local upd_res = node_update_dependents_preserve_position(
|
||||
active,
|
||||
{ no_move = false, restore_position = true }
|
||||
)
|
||||
upd_res.new_node:focus()
|
||||
session.current_nodes[vim.api.nvim_get_current_buf()] = upd_res.new_node
|
||||
end
|
||||
|
@ -273,7 +288,10 @@ local function safe_jump_current(dir, no_move, dry_run)
|
|||
|
||||
-- don't update for -1-node.
|
||||
if not dry_run and node.pos >= 0 then
|
||||
local upd_res = node_update_dependents_preserve_position(node, { no_move = no_move, restore_position = false })
|
||||
local upd_res = node_update_dependents_preserve_position(
|
||||
node,
|
||||
{ no_move = no_move, restore_position = false }
|
||||
)
|
||||
if upd_res.jump_done then
|
||||
return upd_res.new_node
|
||||
else
|
||||
|
|
|
@ -270,7 +270,7 @@ function ChoiceNode:set_choice(choice, current_node)
|
|||
self.active_choice:subtree_set_pos_rgrav(to, -1, true)
|
||||
|
||||
self.active_choice:update_restore()
|
||||
self:update_dependents({own=true, parents=true, children=true})
|
||||
self:update_dependents({ own = true, parents = true, children = true })
|
||||
|
||||
-- Another node may have been entered in update_dependents.
|
||||
self:focus()
|
||||
|
|
|
@ -209,7 +209,7 @@ function DynamicNode:update()
|
|||
-- (and thus have changed text after this update), and all of the
|
||||
-- children's depedents (since they may have dependents outside this
|
||||
-- dynamicNode, who have not yet been updated)
|
||||
self:update_dependents({own=true, children=true, parents=true})
|
||||
self:update_dependents({ own = true, children = true, parents = true })
|
||||
end
|
||||
|
||||
local update_errorstring = [[
|
||||
|
@ -298,7 +298,7 @@ function DynamicNode:update_static()
|
|||
|
||||
tmp:update_static()
|
||||
-- updates own dependents.
|
||||
self:update_dependents_static({own=true, parents=true, children=true})
|
||||
self:update_dependents_static({ own = true, parents = true, children = true })
|
||||
end
|
||||
|
||||
function DynamicNode:exit()
|
||||
|
|
|
@ -60,7 +60,7 @@ function FunctionNode:update()
|
|||
|
||||
-- assume that functionNode can't have a parent as its dependent, there is
|
||||
-- no use for that I think.
|
||||
self:update_dependents({own=true, parents=true})
|
||||
self:update_dependents({ own = true, parents = true })
|
||||
end
|
||||
|
||||
local update_errorstring = [[
|
||||
|
|
|
@ -20,7 +20,7 @@ local function I(pos, static_text, opts)
|
|||
-- will only be needed for 0-node, -1-node isn't set with this.
|
||||
ext_gravities_active = { false, false },
|
||||
inner_active = false,
|
||||
input_active = false
|
||||
input_active = false,
|
||||
}, opts)
|
||||
else
|
||||
return InsertNode:new({
|
||||
|
@ -30,7 +30,7 @@ local function I(pos, static_text, opts)
|
|||
dependents = {},
|
||||
type = types.insertNode,
|
||||
inner_active = false,
|
||||
input_active = false
|
||||
input_active = false,
|
||||
}, opts)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -533,11 +533,11 @@ function Node:set_text(text)
|
|||
|
||||
if self:get_snippet().___static_expanded then
|
||||
self.static_text = text_indented
|
||||
self:update_dependents_static({own=true, parents=true})
|
||||
self:update_dependents_static({ own = true, parents = true })
|
||||
else
|
||||
if self.visible then
|
||||
self:set_text_raw(text_indented)
|
||||
self:update_dependents({own=true, parents=true})
|
||||
self:update_dependents({ own = true, parents = true })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -642,7 +642,6 @@ function Snippet:trigger_expand(current_node, pos_id, env, indent_nodes)
|
|||
-- enter current node, it will contain the new snippet.
|
||||
current_node:input_enter_children()
|
||||
end
|
||||
|
||||
else
|
||||
-- if no parent_node, completely leave.
|
||||
node_util.refocus(current_node, nil)
|
||||
|
@ -757,7 +756,7 @@ function Snippet:trigger_expand(current_node, pos_id, env, indent_nodes)
|
|||
self.mark = mark(old_pos, pos, mark_opts)
|
||||
|
||||
self:update()
|
||||
self:update_dependents({children=true})
|
||||
self:update_dependents({ children = true })
|
||||
|
||||
-- Marks should stay at the beginning of the snippet, only the first mark is needed.
|
||||
start_node.mark = self.nodes[1].mark
|
||||
|
|
|
@ -814,7 +814,6 @@ local function node_subtree_do(node, opts)
|
|||
node:subtree_do(opts)
|
||||
end
|
||||
|
||||
|
||||
local function collect_dependents(node, which, static)
|
||||
local dependents_set = {}
|
||||
|
||||
|
@ -848,7 +847,7 @@ local function collect_dependents(node, which, static)
|
|||
dependents_set[dep] = true
|
||||
end
|
||||
end,
|
||||
static = static
|
||||
static = static,
|
||||
})
|
||||
end
|
||||
|
||||
|
@ -879,5 +878,5 @@ return {
|
|||
nodelist_adjust_rgravs = nodelist_adjust_rgravs,
|
||||
find_node_dependents = find_node_dependents,
|
||||
collect_dependents = collect_dependents,
|
||||
node_subtree_do = node_subtree_do
|
||||
node_subtree_do = node_subtree_do,
|
||||
}
|
||||
|
|
|
@ -2055,7 +2055,9 @@ describe("session", function()
|
|||
-- issue with it.
|
||||
-- => when the dynamicNode is left during `refocus`, the deletion
|
||||
-- will be detected, and snippet removed from the jumplist.
|
||||
exec_lua([[vim.api.nvim_buf_del_extmark(0, ls.session.ns_id, ls.session.current_nodes[1].mark.id)]])
|
||||
exec_lua(
|
||||
[[vim.api.nvim_buf_del_extmark(0, ls.session.ns_id, ls.session.current_nodes[1].mark.id)]]
|
||||
)
|
||||
|
||||
feed("Gofn")
|
||||
expand()
|
||||
|
|
Loading…
Reference in a new issue