Skip to content

Commit

Permalink
Format with stylua
Browse files Browse the repository at this point in the history
  • Loading branch information
L3MON4D3 authored and github-actions[bot] committed Apr 23, 2024
1 parent 31bd5ff commit edf1dd4
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 27 deletions.
44 changes: 31 additions & 13 deletions lua/luasnip/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -167,24 +168,23 @@ 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

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()

Expand All @@ -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.
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lua/luasnip/nodes/choiceNode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions lua/luasnip/nodes/dynamicNode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [[
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion lua/luasnip/nodes/functionNode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [[
Expand Down
4 changes: 2 additions & 2 deletions lua/luasnip/nodes/insertNode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lua/luasnip/nodes/node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lua/luasnip/nodes/snippet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions lua/luasnip/nodes/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -848,7 +847,7 @@ local function collect_dependents(node, which, static)
dependents_set[dep] = true
end
end,
static = static
static = static,
})
end

Expand Down Expand Up @@ -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,
}
4 changes: 3 additions & 1 deletion tests/integration/session_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2030,7 +2030,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()
Expand Down

0 comments on commit edf1dd4

Please sign in to comment.