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 Oct 4, 2023
1 parent 9f81aaf commit 6f964fb
Show file tree
Hide file tree
Showing 11 changed files with 557 additions and 252 deletions.
69 changes: 52 additions & 17 deletions lua/luasnip/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ local function unlink_set_adjacent_as_current_no_log(snippet)
if next_current then
-- if snippet was active before, we need to now set its parent to be no
-- longer inner_active.
if snippet.parent_node == next_current and next_current.inner_active then
if
snippet.parent_node == next_current and next_current.inner_active
then
snippet.parent_node:input_leave_children()
else
-- set no_move.
Expand All @@ -106,7 +108,11 @@ local function unlink_set_adjacent_as_current_no_log(snippet)
-- this won't try to set the previously broken snippet as
-- current, since that link is removed in
-- `remove_from_jumplist`.
unlink_set_adjacent_as_current(next_current.parent.snippet, "Error while setting adjacent snippet as current node: %s", err)
unlink_set_adjacent_as_current(
next_current.parent.snippet,
"Error while setting adjacent snippet as current node: %s",
err
)
end
end
end
Expand Down Expand Up @@ -139,7 +145,12 @@ local function safe_jump_current(dir, no_move, dry_run)
else
local snip = node.parent.snippet

unlink_set_adjacent_as_current(snip, "Removing snippet `%s` due to error %s", snip.trigger, res)
unlink_set_adjacent_as_current(
snip,
"Removing snippet `%s` due to error %s",
snip.trigger,
res
)
return session.current_nodes[vim.api.nvim_get_current_buf()]
end
end
Expand All @@ -160,7 +171,8 @@ end

local function jumpable(dir)
-- node is jumpable if there is a destination.
return jump_destination(dir) ~= session.current_nodes[vim.api.nvim_get_current_buf()]
return jump_destination(dir)
~= session.current_nodes[vim.api.nvim_get_current_buf()]
end

local function expandable()
Expand All @@ -186,7 +198,11 @@ local function in_snippet()
-- if there was an error getting the position, the snippets text was
-- most likely removed, resulting in messed up extmarks -> error.
-- remove the snippet.
unlink_set_adjacent_as_current(snippet, "Error while getting extmark-position: %s", snip_begin_pos)
unlink_set_adjacent_as_current(
snippet,
"Error while getting extmark-position: %s",
snip_begin_pos
)
return
end
local pos = vim.api.nvim_win_get_cursor(0)
Expand Down Expand Up @@ -260,7 +276,8 @@ local function snip_expand(snippet, opts)
session.current_nodes[vim.api.nvim_get_current_buf()] =
opts.jump_into_func(snip)

local buf_snippet_roots = session.snippet_roots[vim.api.nvim_get_current_buf()]
local buf_snippet_roots =
session.snippet_roots[vim.api.nvim_get_current_buf()]
if not session.config.keep_roots and #buf_snippet_roots > 1 then
-- if history is not set, and there is more than one snippet-root,
-- remove the other one.
Expand Down Expand Up @@ -395,7 +412,12 @@ local function safe_choice_action(snip, ...)
else
-- not very elegant, but this way we don't have a near
-- re-implementation of unlink_current.
unlink_set_adjacent_as_current(snip, "Removing snippet `%s` due to error %s", snip.trigger, res)
unlink_set_adjacent_as_current(
snip,
"Removing snippet `%s` due to error %s",
snip.trigger,
res
)
return session.current_nodes[vim.api.nvim_get_current_buf()]
end
end
Expand Down Expand Up @@ -464,19 +486,21 @@ local function active_update_dependents()

local ok, err = pcall(active.update_dependents, active)
if not ok then
log.warn(
)
unlink_set_adjacent_as_current(active.parent.snippet,
log.warn()
unlink_set_adjacent_as_current(
active.parent.snippet,
"Error while updating dependents for snippet %s due to error %s",
active.parent.snippet.trigger,
err)
err
)
return
end

-- 'restore' orientation of extmarks, may have been changed by some set_text or similar.
ok, err = pcall(active.focus, active)
if not ok then
unlink_set_adjacent_as_current(active.parent.snippet,
unlink_set_adjacent_as_current(
active.parent.snippet,
"Error while entering node in snippet %s: %s",
active.parent.snippet.trigger,
err
Expand Down Expand Up @@ -578,7 +602,11 @@ local function unlink_current_if_deleted()
-- * textnodes that should contain text still do so, and
-- * that extmarks still fulfill all expectations (should be successive, no gaps, etc.)
if not snippet:extmarks_valid() then
unlink_set_adjacent_as_current(snippet, "Detected deletion of snippet `%s`, removing it", snippet.trigger)
unlink_set_adjacent_as_current(
snippet,
"Detected deletion of snippet `%s`, removing it",
snippet.trigger
)
end
end

Expand All @@ -605,7 +633,11 @@ local function exit_out_of_region(node)
pcall(snippet.mark.pos_begin_end, snippet.mark)

if not ok then
unlink_set_adjacent_as_current(snippet, "Error while getting extmark-position: %s", snip_begin_pos)
unlink_set_adjacent_as_current(
snippet,
"Error while getting extmark-position: %s",
snip_begin_pos
)
return
end

Expand Down Expand Up @@ -744,7 +776,7 @@ local function activate_node(opts)
local _, _, _, node = node_util.snippettree_find_undamaged_node(pos, {
tree_respect_rgravs = false,
tree_preference = node_util.binarysearch_preference.inside,
snippet_mode = "interactive"
snippet_mode = "interactive",
})

if not node then
Expand Down Expand Up @@ -774,7 +806,10 @@ local function activate_node(opts)
end
end

node_util.refocus(session.current_nodes[vim.api.nvim_get_current_buf()], node)
node_util.refocus(
session.current_nodes[vim.api.nvim_get_current_buf()],
node
)
if select then
-- input_enter node again, to get highlight and the like.
-- One side-effect of this is that an event will be execute twice, but I
Expand Down Expand Up @@ -856,7 +891,7 @@ ls = util.lazy_table({
setup = require("luasnip.config").setup,
extend_decorator = extend_decorator,
log = require("luasnip.util.log"),
activate_node = activate_node
activate_node = activate_node,
}, ls_lazy)

return ls
12 changes: 8 additions & 4 deletions lua/luasnip/nodes/insertNode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ function ExitNode:jump_from(dir, no_move, dry_run)
self:init_dry_run_inner_active(dry_run)

local next_node = util.ternary(dir == 1, self.next, self.prev)
local next_inner_node = util.ternary(dir == 1, self.inner_first, self.inner_last)
local next_inner_node =
util.ternary(dir == 1, self.inner_first, self.inner_last)

if next_inner_node then
self:input_enter_children(dry_run)
Expand All @@ -199,7 +200,8 @@ function ExitNode:jump_from(dir, no_move, dry_run)
-- not have children active if jump_from is called.

-- true: don't move
local target_node = next_node:jump_into(dir, true, next_node_dry_run)
local target_node =
next_node:jump_into(dir, true, next_node_dry_run)
-- if there is no node that can serve as jump-target, just remain
-- here.
-- Regular insertNodes don't have to handle this, since there is
Expand All @@ -220,7 +222,8 @@ function InsertNode:jump_from(dir, no_move, dry_run)
self:init_dry_run_inner_active(dry_run)

local next_node = util.ternary(dir == 1, self.next, self.prev)
local next_inner_node = util.ternary(dir == 1, self.inner_first, self.inner_last)
local next_inner_node =
util.ternary(dir == 1, self.inner_first, self.inner_last)

if next_inner_node then
self:input_enter_children(dry_run)
Expand Down Expand Up @@ -308,7 +311,8 @@ function InsertNode:subtree_set_pos_rgrav(pos, direction, rgrav)
direction,
rgrav,
-- don't assume that the child-snippets are all adjacent.
false)
false
)
end

function InsertNode:subtree_set_rgrav(rgrav)
Expand Down
17 changes: 13 additions & 4 deletions lua/luasnip/nodes/node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ local function focus_node(self, lrgrav, rrgrav)
-- dynamicNode, for example, the generated snippets parent is not the
-- dynamicNode, but its parent).
-- also: don't need to check for nil, because the
local node_above = nodes_path[i+1]
local node_above = nodes_path[i + 1]
if node_above then
node_above:set_sibling_rgravs(
node,
Expand Down Expand Up @@ -603,14 +603,23 @@ end

function Node:linkable()
-- linkable if insert or exitNode.
return vim.tbl_contains({types.insertNode, types.exitNode}, rawget(self, "type"))
return vim.tbl_contains(
{ types.insertNode, types.exitNode },
rawget(self, "type")
)
end
function Node:interactive()
-- interactive if immediately inside choiceNode.
return vim.tbl_contains({types.insertNode, types.exitNode}, rawget(self, "type")) or rawget(self, "choice") ~= nil
return vim.tbl_contains(
{ types.insertNode, types.exitNode },
rawget(self, "type")
) or rawget(self, "choice") ~= nil
end
function Node:leaf()
return vim.tbl_contains({types.textNode, types.functionNode, types.insertNode, types.exitNode}, rawget(self, "type"))
return vim.tbl_contains(
{ types.textNode, types.functionNode, types.insertNode, types.exitNode },
rawget(self, "type")
)
end

return {
Expand Down
Loading

0 comments on commit 6f964fb

Please sign in to comment.