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 47602ea commit 350ba61
Show file tree
Hide file tree
Showing 16 changed files with 350 additions and 236 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
23 changes: 15 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 @@ -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,17 +190,23 @@ 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
feedkeys.move_to(util.pos_add(node.mark:get_endpoint(1), data.cursor_end_relative))
feedkeys.move_to(
util.pos_add(node.mark:get_endpoint(1), data.cursor_end_relative)
)
end
end

Expand Down Expand Up @@ -301,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 @@ -1032,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
7 changes: 2 additions & 5 deletions lua/luasnip/nodes/choiceNode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,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 @@ -279,7 +276,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 @@ -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
20 changes: 8 additions & 12 deletions lua/luasnip/nodes/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,7 @@ end

local function linkable_node(node)
-- node.type has to be one of insertNode, exitNode.
return vim.tbl_contains(
{ types.insertNode, types.exitNode },
node.type
)
return vim.tbl_contains({ types.insertNode, types.exitNode }, node.type)
end

-- mainly used internally, by binarysearch_pos.
Expand All @@ -198,10 +195,7 @@ end
-- feel appropriate (higher runtime), most cases should be served well by this
-- heuristic.
local function non_linkable_node(node)
return vim.tbl_contains(
{ types.textNode, types.functionNode },
node.type
)
return vim.tbl_contains({ types.textNode, types.functionNode }, node.type)
end
-- return whether a node is certainly (not) interactive.
-- Coincindentially, the same nodes as (non-)linkable ones, but since there is a
Expand Down Expand Up @@ -857,9 +851,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 +883,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 350ba61

Please sign in to comment.