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 6, 2024
1 parent 20f80be commit 8ee6626
Show file tree
Hide file tree
Showing 14 changed files with 325 additions and 208 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
19 changes: 12 additions & 7 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 @@ -175,7 +174,8 @@ local function store_cursor_node_relative(node)
util.pos_sub(cursor_state.pos, node.mark:get_endpoint(1))

if cursor_state.pos_end then
snip_data.selection_other_end_end_relative = util.pos_sub(cursor_state.pos_end, node.mark:get_endpoint(1))
snip_data.selection_other_end_end_relative =
util.pos_sub(cursor_state.pos_end, node.mark:get_endpoint(1))
end

data[snip] = snip_data
Expand All @@ -190,14 +190,18 @@ 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 restore_cursor_pos_relative(node, data)
if data.selection_other_end_end_relative then
-- is a selection => restore it.
local selection_from = util.pos_add(node.mark:get_endpoint(1), data.cursor_end_relative)
local selection_to = util.pos_add(node.mark:get_endpoint(1), data.selection_other_end_end_relative)
local selection_from =
util.pos_add(node.mark:get_endpoint(1), data.cursor_end_relative)
local selection_to = util.pos_add(
node.mark:get_endpoint(1),
data.selection_other_end_end_relative
)
feedkeys.select_range(selection_from, selection_to)
else
util.set_cursor_0ind(
Expand Down Expand Up @@ -303,7 +307,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 @@ -1034,7 +1039,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
2 changes: 1 addition & 1 deletion lua/luasnip/nodes/choiceNode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function ChoiceNode:set_choice(choice, current_node)
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
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 @@ -166,7 +166,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 @@ -268,8 +273,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 @@ -321,7 +331,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 @@ -356,7 +370,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 @@ -400,12 +423,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
10 changes: 6 additions & 4 deletions lua/luasnip/nodes/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -857,9 +857,11 @@ local function collect_dependents(node, which, static)
end

local function str_args(args)
return args and vim.tbl_map(function(arg)
return snippet_string.isinstance(arg) and vim.split(arg:str(), "\n") or arg
end, args)
return args
and vim.tbl_map(function(arg)
return snippet_string.isinstance(arg) and vim.split(arg:str(), "\n")
or arg
end, args)
end

return {
Expand Down Expand Up @@ -887,5 +889,5 @@ return {
find_node_dependents = find_node_dependents,
collect_dependents = collect_dependents,
node_subtree_do = node_subtree_do,
str_args = str_args
str_args = str_args,
}
Loading

0 comments on commit 8ee6626

Please sign in to comment.