Skip to content

Commit 4af90c0

Browse files
L3MON4D3github-actions[bot]
authored andcommitted
Format with stylua
1 parent 6f585b1 commit 4af90c0

File tree

17 files changed

+457
-314
lines changed

17 files changed

+457
-314
lines changed

lua/luasnip/config.lua

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,14 @@ c = {
101101
require("luasnip").unlink_current_if_deleted
102102
)
103103
end
104-
ls_autocmd(
105-
session.config.update_events,
106-
function()
107-
-- don't update due to events if an update due to luasnip is pending anyway.
108-
-- (Also, this would be bad because luasnip may not be in an
109-
-- consistent state whenever an autocommand is triggered)
110-
if not session.jump_active then
111-
require("luasnip").active_update_dependents()
112-
end
104+
ls_autocmd(session.config.update_events, function()
105+
-- don't update due to events if an update due to luasnip is pending anyway.
106+
-- (Also, this would be bad because luasnip may not be in an
107+
-- consistent state whenever an autocommand is triggered)
108+
if not session.jump_active then
109+
require("luasnip").active_update_dependents()
113110
end
114-
)
111+
end)
115112
if session.config.region_check_events ~= nil then
116113
ls_autocmd(session.config.region_check_events, function()
117114
require("luasnip").exit_out_of_region(

lua/luasnip/extras/select_choice.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ local function set_choice_callback(data)
99
end
1010
-- feed+immediately execute i to enter INSERT after vim.ui.input closes.
1111
-- vim.api.nvim_feedkeys("i", "x", false)
12-
ls.set_choice(indx, {cursor_restore_data = data})
12+
ls.set_choice(indx, { cursor_restore_data = data })
1313
end
1414
end
1515

lua/luasnip/init.lua

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ local function no_region_check_wrap(fn, ...)
3131
return fn_res
3232
end
3333

34-
3534
local function get_active_snip()
3635
local node = session.current_nodes[vim.api.nvim_get_current_buf()]
3736
if not node then
@@ -153,7 +152,7 @@ local function get_corresponding_node(parent, data)
153152
return parent:find_node(function(test_node)
154153
return (test_node.store_id == data.store_id)
155154
or (data.key ~= nil and test_node.key == data.key)
156-
end, {find_in_child_snippets = true})
155+
end, { find_in_child_snippets = true })
157156
end
158157

159158
local function node_update_dependents_preserve_position(node, current, opts)
@@ -182,7 +181,10 @@ local function node_update_dependents_preserve_position(node, current, opts)
182181
if not opts.no_move and opts.restore_position then
183182
-- node is visible: restore position.
184183
local active_snippet = current:get_snippet()
185-
node_util.restore_cursor_pos_relative(current, restore_data[active_snippet])
184+
node_util.restore_cursor_pos_relative(
185+
current,
186+
restore_data[active_snippet]
187+
)
186188
end
187189

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

228230
if not opts.no_move and opts.restore_position then
229231
-- node is visible: restore position
230-
node_util.restore_cursor_pos_relative(new_current, snip_restore_data)
232+
node_util.restore_cursor_pos_relative(
233+
new_current,
234+
snip_restore_data
235+
)
231236
end
232237

233238
return { jump_done = false, new_current = new_current }
@@ -253,7 +258,8 @@ local function update_dependents(node)
253258
{ no_move = false, restore_position = true }
254259
)
255260
upd_res.new_current:focus()
256-
session.current_nodes[vim.api.nvim_get_current_buf()] = upd_res.new_current
261+
session.current_nodes[vim.api.nvim_get_current_buf()] =
262+
upd_res.new_current
257263
end
258264
end
259265
local function active_update_dependents()
@@ -581,7 +587,8 @@ local function change_choice(val, opts)
581587

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

586593
local new_active = no_region_check_wrap(
587594
safe_choice_action,
@@ -598,7 +605,8 @@ end
598605

599606
local function set_choice(choice_indx, opts)
600607
local current_node = session.current_nodes[vim.api.nvim_get_current_buf()]
601-
local restore_data = opts and opts.cursor_restore_data or node_util.store_cursor_node_relative(current_node)
608+
local restore_data = opts and opts.cursor_restore_data
609+
or node_util.store_cursor_node_relative(current_node)
602610

603611
local active_choice =
604612
session.active_choice_nodes[vim.api.nvim_get_current_buf()]
@@ -995,7 +1003,7 @@ ls = lazy_table({
9951003
extend_decorator = extend_decorator,
9961004
log = require("luasnip.util.log"),
9971005
activate_node = activate_node,
998-
no_region_check_wrap = no_region_check_wrap
1006+
no_region_check_wrap = no_region_check_wrap,
9991007
}, ls_lazy)
10001008

10011009
return ls

lua/luasnip/nodes/choiceNode.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,7 @@ function ChoiceNode:get_static_text()
169169
end
170170

171171
function ChoiceNode:get_docstring()
172-
return util.string_wrap(
173-
self.choices[1]:get_docstring(),
174-
self.pos
175-
)
172+
return util.string_wrap(self.choices[1]:get_docstring(), self.pos)
176173
end
177174

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

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

286283
node_util.refocus(self, target_node)
287-
node_util.restore_cursor_pos_relative(target_node, cursor_restore_data[target_node.parent.snippet])
284+
node_util.restore_cursor_pos_relative(
285+
target_node,
286+
cursor_restore_data[target_node.parent.snippet]
287+
)
288288

289289
return target_node
290290
end

lua/luasnip/nodes/dynamicNode.lua

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,12 @@ function DynamicNode:update()
168168
tmp = SnippetNode(nil, {})
169169
else
170170
-- also enter node here.
171-
tmp = self.fn(effective_args, self.parent, nil, unpack(self.user_args))
171+
tmp = self.fn(
172+
effective_args,
173+
self.parent,
174+
nil,
175+
unpack(self.user_args)
176+
)
172177
end
173178
end
174179

@@ -270,8 +275,13 @@ function DynamicNode:update_static()
270275
tmp = SnippetNode(nil, {})
271276
else
272277
-- also enter node here.
273-
ok, tmp =
274-
pcall(self.fn, effective_args, self.parent, nil, unpack(self.user_args))
278+
ok, tmp = pcall(
279+
self.fn,
280+
effective_args,
281+
self.parent,
282+
nil,
283+
unpack(self.user_args)
284+
)
275285
end
276286
end
277287
if not ok then
@@ -323,7 +333,11 @@ function DynamicNode:update_static()
323333

324334
tmp:update_static()
325335
-- updates own dependents.
326-
self:update_dependents_static({ own = true, parents = true, children = true })
336+
self:update_dependents_static({
337+
own = true,
338+
parents = true,
339+
children = true,
340+
})
327341
end
328342

329343
function DynamicNode:exit()
@@ -358,7 +372,11 @@ function DynamicNode:update_restore()
358372
local str_args = node_util.str_args(args)
359373

360374
-- only insert snip if it is not currently visible!
361-
if self.snip and not self.snip.visible and vim.deep_equal(str_args, self.last_args) then
375+
if
376+
self.snip
377+
and not self.snip.visible
378+
and vim.deep_equal(str_args, self.last_args)
379+
then
362380
local tmp = self.snip
363381

364382
-- position might (will probably!!) still have changed, so update it

lua/luasnip/nodes/insertNode.lua

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,15 @@ function InsertNode:get_snippetstring()
343343
local self_from, self_to = self.mark:pos_begin_end_raw()
344344
-- only do one get_text, and establish relative offsets partition this
345345
-- text.
346-
local ok, text = pcall(vim.api.nvim_buf_get_text, 0, self_from[1], self_from[2], self_to[1], self_to[2], {})
346+
local ok, text = pcall(
347+
vim.api.nvim_buf_get_text,
348+
0,
349+
self_from[1],
350+
self_from[2],
351+
self_to[1],
352+
self_to[2],
353+
{}
354+
)
347355

348356
local snippetstring = snippet_string.new()
349357

@@ -353,17 +361,32 @@ function InsertNode:get_snippetstring()
353361
return snippetstring
354362
end
355363

356-
local current = {0,0}
364+
local current = { 0, 0 }
357365
for _, snip in ipairs(self:child_snippets()) do
358366
local snip_from, snip_to = snip.mark:pos_begin_end_raw()
359367
local snip_from_base_rel = util.pos_offset(self_from, snip_from)
360-
local snip_to_base_rel = util.pos_offset(self_from, snip_to)
361-
362-
snippetstring:append_text(str_util.multiline_substr(text, current, snip_from_base_rel))
363-
snippetstring:append_snip(snip, str_util.multiline_substr(text, snip_from_base_rel, snip_to_base_rel))
368+
local snip_to_base_rel = util.pos_offset(self_from, snip_to)
369+
370+
snippetstring:append_text(
371+
str_util.multiline_substr(text, current, snip_from_base_rel)
372+
)
373+
snippetstring:append_snip(
374+
snip,
375+
str_util.multiline_substr(
376+
text,
377+
snip_from_base_rel,
378+
snip_to_base_rel
379+
)
380+
)
364381
current = snip_to_base_rel
365382
end
366-
snippetstring:append_text(str_util.multiline_substr(text, current, util.pos_offset(self_from, self_to)))
383+
snippetstring:append_text(
384+
str_util.multiline_substr(
385+
text,
386+
current,
387+
util.pos_offset(self_from, self_to)
388+
)
389+
)
367390

368391
return snippetstring
369392
end
@@ -397,12 +420,18 @@ function InsertNode:put_initial(pos)
397420
-- index.
398421
true,
399422
-- don't enter snippets, we want to find the position of this node.
400-
node_util.binarysearch_preference.outside)
423+
node_util.binarysearch_preference.outside
424+
)
401425

402426
for snip in self.static_text:iter_snippets() do
403427
-- don't have to pass a current_node, we don't need it since we can
404428
-- certainly link the snippet into this insertNode.
405-
snip:insert_into_jumplist(nil, self, self.parent.snippet.child_snippets, child_snippet_idx)
429+
snip:insert_into_jumplist(
430+
nil,
431+
self,
432+
self.parent.snippet.child_snippets,
433+
child_snippet_idx
434+
)
406435

407436
child_snippet_idx = child_snippet_idx + 1
408437
end

lua/luasnip/nodes/node.lua

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,13 @@ local function get_args(node, get_text_func_name, static)
255255
-- * we are doing a static update and it is not static_visible or
256256
-- visible (this second condition is to allow the docstring-generation
257257
-- to be improved by data provided after the expansion)
258-
if argnode and ((static and (argnode.static_visible or argnode.visible)) or (not static and argnode.visible)) then
258+
if
259+
argnode
260+
and (
261+
(static and (argnode.static_visible or argnode.visible))
262+
or (not static and argnode.visible)
263+
)
264+
then
259265
if not static then
260266
-- Don't store (aka call get_snippetstring) if this is a static
261267
-- update (there will be no associated buffer-region!) and
@@ -576,17 +582,12 @@ end
576582

577583
function Node:linkable()
578584
-- linkable if insert or exitNode.
579-
return vim.tbl_contains(
580-
{ types.insertNode, types.exitNode },
581-
self.type
582-
)
585+
return vim.tbl_contains({ types.insertNode, types.exitNode }, self.type)
583586
end
584587
function Node:interactive()
585588
-- interactive if immediately inside choiceNode.
586-
return vim.tbl_contains(
587-
{ types.insertNode, types.exitNode },
588-
self.type
589-
) or self.choice ~= nil
589+
return vim.tbl_contains({ types.insertNode, types.exitNode }, self.type)
590+
or self.choice ~= nil
590591
end
591592
function Node:leaf()
592593
return vim.tbl_contains(

0 commit comments

Comments
 (0)