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 Nov 7, 2024
1 parent b55707f commit 6df134e
Show file tree
Hide file tree
Showing 17 changed files with 457 additions and 314 deletions.
17 changes: 7 additions & 10 deletions lua/luasnip/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,14 @@ c = {
require("luasnip").unlink_current_if_deleted
)
end
ls_autocmd(
session.config.update_events,
function()
-- don't update due to events if an update due to luasnip is pending anyway.
-- (Also, this would be bad because luasnip may not be in an
-- consistent state whenever an autocommand is triggered)
if not session.jump_active then
require("luasnip").active_update_dependents()
end
ls_autocmd(session.config.update_events, function()
-- don't update due to events if an update due to luasnip is pending anyway.
-- (Also, this would be bad because luasnip may not be in an
-- consistent state whenever an autocommand is triggered)
if not session.jump_active then
require("luasnip").active_update_dependents()
end
)
end)
if session.config.region_check_events ~= nil then
ls_autocmd(session.config.region_check_events, function()
require("luasnip").exit_out_of_region(
Expand Down
2 changes: 1 addition & 1 deletion lua/luasnip/extras/select_choice.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ local function set_choice_callback(data)
end
-- feed+immediately execute i to enter INSERT after vim.ui.input closes.
-- vim.api.nvim_feedkeys("i", "x", false)
ls.set_choice(indx, {cursor_restore_data = data})
ls.set_choice(indx, { cursor_restore_data = data })
end
end

Expand Down
24 changes: 16 additions & 8 deletions lua/luasnip/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ local function no_region_check_wrap(fn, ...)
return fn_res
end


local function get_active_snip()
local node = session.current_nodes[vim.api.nvim_get_current_buf()]
if not node then
Expand Down Expand Up @@ -153,7 +152,7 @@ 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)
end, {find_in_child_snippets = true})
end, { find_in_child_snippets = true })
end

local function node_update_dependents_preserve_position(node, current, opts)
Expand Down Expand Up @@ -182,7 +181,10 @@ local function node_update_dependents_preserve_position(node, current, opts)
if not opts.no_move and opts.restore_position then
-- node is visible: restore position.
local active_snippet = current:get_snippet()
node_util.restore_cursor_pos_relative(current, restore_data[active_snippet])
node_util.restore_cursor_pos_relative(
current,
restore_data[active_snippet]
)
end

return { jump_done = false, new_current = current }
Expand Down Expand Up @@ -227,7 +229,10 @@ local function node_update_dependents_preserve_position(node, current, opts)

if not opts.no_move and opts.restore_position then
-- node is visible: restore position
node_util.restore_cursor_pos_relative(new_current, snip_restore_data)
node_util.restore_cursor_pos_relative(
new_current,
snip_restore_data
)
end

return { jump_done = false, new_current = new_current }
Expand All @@ -253,7 +258,8 @@ local function update_dependents(node)
{ no_move = false, restore_position = true }
)
upd_res.new_current:focus()
session.current_nodes[vim.api.nvim_get_current_buf()] = upd_res.new_current
session.current_nodes[vim.api.nvim_get_current_buf()] =
upd_res.new_current
end
end
local function active_update_dependents()
Expand Down Expand Up @@ -581,7 +587,8 @@ local function change_choice(val, opts)

-- if the active choice exists current_node still does.
local current_node = session.current_nodes[vim.api.nvim_get_current_buf()]
local restore_data = opts and opts.cursor_restore_data or node_util.store_cursor_node_relative(current_node)
local restore_data = opts and opts.cursor_restore_data
or node_util.store_cursor_node_relative(current_node)

local new_active = no_region_check_wrap(
safe_choice_action,
Expand All @@ -598,7 +605,8 @@ end

local function set_choice(choice_indx, opts)
local current_node = session.current_nodes[vim.api.nvim_get_current_buf()]
local restore_data = opts and opts.cursor_restore_data or node_util.store_cursor_node_relative(current_node)
local restore_data = opts and opts.cursor_restore_data
or node_util.store_cursor_node_relative(current_node)

local active_choice =
session.active_choice_nodes[vim.api.nvim_get_current_buf()]
Expand Down Expand Up @@ -995,7 +1003,7 @@ ls = lazy_table({
extend_decorator = extend_decorator,
log = require("luasnip.util.log"),
activate_node = activate_node,
no_region_check_wrap = no_region_check_wrap
no_region_check_wrap = no_region_check_wrap,
}, ls_lazy)

return ls
12 changes: 6 additions & 6 deletions lua/luasnip/nodes/choiceNode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,7 @@ function ChoiceNode:get_static_text()
end

function ChoiceNode:get_docstring()
return util.string_wrap(
self.choices[1]:get_docstring(),
self.pos
)
return util.string_wrap(self.choices[1]:get_docstring(), self.pos)
end

function ChoiceNode:jump_into(dir, no_move, dry_run)
Expand Down Expand Up @@ -276,15 +273,18 @@ function ChoiceNode:set_choice(choice, current_node, cursor_restore_data)
if self.restore_cursor then
local target_node = self:find_node(function(test_node)
return test_node.change_choice_id == change_choice_id
end, {find_in_child_snippets = true})
end, { find_in_child_snippets = true })

if target_node then
-- the node that the cursor was in when changeChoice was called
-- exists in the active choice! Enter it and all nodes between it
-- and this choiceNode, then set the cursor.

node_util.refocus(self, target_node)
node_util.restore_cursor_pos_relative(target_node, cursor_restore_data[target_node.parent.snippet])
node_util.restore_cursor_pos_relative(
target_node,
cursor_restore_data[target_node.parent.snippet]
)

return target_node
end
Expand Down
28 changes: 23 additions & 5 deletions lua/luasnip/nodes/dynamicNode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ function DynamicNode:update()
tmp = SnippetNode(nil, {})
else
-- also enter node here.
tmp = self.fn(effective_args, self.parent, nil, unpack(self.user_args))
tmp = self.fn(
effective_args,
self.parent,
nil,
unpack(self.user_args)
)
end
end

Expand Down Expand Up @@ -270,8 +275,13 @@ function DynamicNode:update_static()
tmp = SnippetNode(nil, {})
else
-- also enter node here.
ok, tmp =
pcall(self.fn, effective_args, self.parent, nil, unpack(self.user_args))
ok, tmp = pcall(
self.fn,
effective_args,
self.parent,
nil,
unpack(self.user_args)
)
end
end
if not ok then
Expand Down Expand Up @@ -323,7 +333,11 @@ 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 Expand Up @@ -358,7 +372,11 @@ function DynamicNode:update_restore()
local str_args = node_util.str_args(args)

-- only insert snip if it is not currently visible!
if self.snip and not self.snip.visible and vim.deep_equal(str_args, self.last_args) then
if
self.snip
and not self.snip.visible
and vim.deep_equal(str_args, self.last_args)
then
local tmp = self.snip

-- position might (will probably!!) still have changed, so update it
Expand Down
47 changes: 38 additions & 9 deletions lua/luasnip/nodes/insertNode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,15 @@ function InsertNode:get_snippetstring()
local self_from, self_to = self.mark:pos_begin_end_raw()
-- only do one get_text, and establish relative offsets partition this
-- text.
local ok, text = pcall(vim.api.nvim_buf_get_text, 0, self_from[1], self_from[2], self_to[1], self_to[2], {})
local ok, text = pcall(
vim.api.nvim_buf_get_text,
0,
self_from[1],
self_from[2],
self_to[1],
self_to[2],
{}
)

local snippetstring = snippet_string.new()

Expand All @@ -353,17 +361,32 @@ function InsertNode:get_snippetstring()
return snippetstring
end

local current = {0,0}
local current = { 0, 0 }
for _, snip in ipairs(self:child_snippets()) do
local snip_from, snip_to = snip.mark:pos_begin_end_raw()
local snip_from_base_rel = util.pos_offset(self_from, snip_from)
local snip_to_base_rel = util.pos_offset(self_from, snip_to)

snippetstring:append_text(str_util.multiline_substr(text, current, snip_from_base_rel))
snippetstring:append_snip(snip, str_util.multiline_substr(text, snip_from_base_rel, snip_to_base_rel))
local snip_to_base_rel = util.pos_offset(self_from, snip_to)

snippetstring:append_text(
str_util.multiline_substr(text, current, snip_from_base_rel)
)
snippetstring:append_snip(
snip,
str_util.multiline_substr(
text,
snip_from_base_rel,
snip_to_base_rel
)
)
current = snip_to_base_rel
end
snippetstring:append_text(str_util.multiline_substr(text, current, util.pos_offset(self_from, self_to)))
snippetstring:append_text(
str_util.multiline_substr(
text,
current,
util.pos_offset(self_from, self_to)
)
)

return snippetstring
end
Expand Down Expand Up @@ -397,12 +420,18 @@ function InsertNode:put_initial(pos)
-- index.
true,
-- don't enter snippets, we want to find the position of this node.
node_util.binarysearch_preference.outside)
node_util.binarysearch_preference.outside
)

for snip in self.static_text:iter_snippets() do
-- don't have to pass a current_node, we don't need it since we can
-- certainly link the snippet into this insertNode.
snip:insert_into_jumplist(nil, self, self.parent.snippet.child_snippets, child_snippet_idx)
snip:insert_into_jumplist(
nil,
self,
self.parent.snippet.child_snippets,
child_snippet_idx
)

child_snippet_idx = child_snippet_idx + 1
end
Expand Down
19 changes: 10 additions & 9 deletions lua/luasnip/nodes/node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,13 @@ local function get_args(node, get_text_func_name, static)
-- * we are doing a static update and it is not static_visible or
-- visible (this second condition is to allow the docstring-generation
-- to be improved by data provided after the expansion)
if argnode and ((static and (argnode.static_visible or argnode.visible)) or (not static and argnode.visible)) then
if
argnode
and (
(static and (argnode.static_visible or argnode.visible))
or (not static and argnode.visible)
)
then
if not static then
-- Don't store (aka call get_snippetstring) if this is a static
-- update (there will be no associated buffer-region!) and
Expand Down Expand Up @@ -576,17 +582,12 @@ end

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

0 comments on commit 6df134e

Please sign in to comment.