From 22d4a1a9a8715c405947a46edcbb71dc7022de6b Mon Sep 17 00:00:00 2001 From: L3MON4D3 Date: Sun, 2 Jul 2023 19:45:36 +0000 Subject: [PATCH] Format with stylua --- lua/luasnip/init.lua | 6 ++++- lua/luasnip/nodes/snippet.lua | 50 +++++++++++++++++++++++++++-------- lua/luasnip/nodes/util.lua | 10 +++---- lua/luasnip/session/init.lua | 4 +-- lua/luasnip/util/util.lua | 2 +- 5 files changed, 52 insertions(+), 20 deletions(-) diff --git a/lua/luasnip/init.lua b/lua/luasnip/init.lua index d2fbe9712..85efd24e3 100644 --- a/lua/luasnip/init.lua +++ b/lua/luasnip/init.lua @@ -622,7 +622,11 @@ local function exit_out_of_region(node) pcall(snippet.mark.pos_begin_end, snippet.mark) if not ok then - remove_snip_set_adjacent_as_current(snippet, "Error while getting extmark-position: %s", snip_begin_pos) + remove_snip_set_adjacent_as_current( + snippet, + "Error while getting extmark-position: %s", + snip_begin_pos + ) end -- stylua: ignore diff --git a/lua/luasnip/nodes/snippet.lua b/lua/luasnip/nodes/snippet.lua index a069b3904..e3058216f 100644 --- a/lua/luasnip/nodes/snippet.lua +++ b/lua/luasnip/nodes/snippet.lua @@ -319,7 +319,7 @@ local function _S(snip, nodes, opts) -- list of snippets expanded within the region of this snippet. -- sorted by their buffer-position, for quick searching. - child_snippets = {} + child_snippets = {}, }), opts ) @@ -446,13 +446,15 @@ extend_decorator.register(ISN, { arg_indx = 4 }) -- * the index this snippet would be at if inserted into that list local function find_snippettree_position(pos) local prev_parent = nil - local prev_parent_children = session.snippet_roots[vim.api.nvim_get_current_buf()] + local prev_parent_children = + session.snippet_roots[vim.api.nvim_get_current_buf()] while true do -- `false`: if pos is on the boundary of a snippet, consider it as -- outside the snippet (in other words, prefer shifting the snippet to -- continuing the search inside it.) - local found_parent, child_indx = node_util.binarysearch_pos(prev_parent_children, pos, false) + local found_parent, child_indx = + node_util.binarysearch_pos(prev_parent_children, pos, false) if not found_parent then -- prev_parent is nil if this snippet is expanded at the top-level. return prev_parent, prev_parent_children, child_indx @@ -473,7 +475,9 @@ function Snippet:remove_from_jumplist() self:exit() - local sibling_list = self.parent_node ~= nil and self.parent_node.parent.snippet.child_snippets or session.snippet_roots + local sibling_list = self.parent_node ~= nil + and self.parent_node.parent.snippet.child_snippets + or session.snippet_roots local self_indx for i, snip in ipairs(sibling_list) do if snip == self then @@ -501,8 +505,15 @@ function Snippet:remove_from_jumplist() end end -local function insert_into_jumplist(snippet, start_node, current_node, parent_node, sibling_snippets, own_indx) - local prev_snippet = sibling_snippets[own_indx-1] +local function insert_into_jumplist( + snippet, + start_node, + current_node, + parent_node, + sibling_snippets, + own_indx +) + local prev_snippet = sibling_snippets[own_indx - 1] -- have not yet inserted self!! local next_snippet = sibling_snippets[own_indx] @@ -519,7 +530,10 @@ local function insert_into_jumplist(snippet, start_node, current_node, parent_no end if parent_node then - local can_link_parent_node = vim.tbl_contains({types.insertNode, types.snippetNode}, rawget(parent_node, "type")) + local can_link_parent_node = vim.tbl_contains( + { types.insertNode, types.snippetNode }, + rawget(parent_node, "type") + ) -- snippetNode (which has to be empty to be viable here) and -- insertNode can both deal with inserting a snippet inside them -- (ie. hooking it up st. it can be visited after jumping back to @@ -576,7 +590,8 @@ end function Snippet:trigger_expand(current_node, pos_id, env) local pos = vim.api.nvim_buf_get_extmark_by_id(0, session.ns_id, pos_id, {}) - local parent_snippet, sibling_snippets, own_indx = find_snippettree_position(pos) + local parent_snippet, sibling_snippets, own_indx = + find_snippettree_position(pos) -- may be nil, ofc. local parent_node = parent_snippet and parent_snippet:node_at(pos) @@ -668,7 +683,14 @@ function Snippet:trigger_expand(current_node, pos_id, env) -- parent_node is nil if the snippet is toplevel. self.parent_node = parent_node - insert_into_jumplist(self, start_node, current_node, parent_node, sibling_snippets, own_indx) + insert_into_jumplist( + self, + start_node, + current_node, + parent_node, + sibling_snippets, + own_indx + ) end -- returns copy of snip if it matches, nil if not. @@ -1287,10 +1309,16 @@ end -- pos-column has to be a byte-index, not a display-column. function Snippet:smallest_node_at(pos) local self_from, self_to = self.mark:pos_begin_end_raw() - assert(util.pos_cmp(self_from, pos) <= 0 and util.pos_cmp(pos, self_to) <= 0, "pos is not inside the snippet.") + assert( + util.pos_cmp(self_from, pos) <= 0 and util.pos_cmp(pos, self_to) <= 0, + "pos is not inside the snippet." + ) local smallest_node = self:node_at(pos) - assert(smallest_node ~= nil, "could not find a smallest node (very unexpected)") + assert( + smallest_node ~= nil, + "could not find a smallest node (very unexpected)" + ) return smallest_node end diff --git a/lua/luasnip/nodes/util.lua b/lua/luasnip/nodes/util.lua index 42a4afb86..cd0be33c4 100644 --- a/lua/luasnip/nodes/util.lua +++ b/lua/luasnip/nodes/util.lua @@ -99,7 +99,7 @@ local function leave_nodes_between(parent, child, no_move) -- entirely (because we stop at nodes[2], and handle nodes[1] -- separately) nodes[i]:input_leave(no_move) - nodes[i-1]:input_leave_children() + nodes[i - 1]:input_leave_children() end nodes[1]:input_leave(no_move) end @@ -110,7 +110,7 @@ local function enter_nodes_between(parent, child, no_move) return end - for i = 1, #nodes-1 do + for i = 1, #nodes - 1 do -- only enter children for nodes before the last (lowest) one. nodes[i]:input_enter(no_move) nodes[i]:input_enter_children() @@ -185,7 +185,7 @@ local cmp_functions = { end, boundary_outside_greater = function(pos, range_to) return util.pos_cmp(pos, range_to) >= 0 - end + end, } -- `nodes` is a list of nodes ordered by their occurrence in the buffer. -- `pos` is a row-column-tuble, byte-columns, and we return the node the LEFT @@ -203,7 +203,7 @@ local cmp_functions = { -- * if it is false, pos has to be fully inside a node to be considered inside -- it. If pos is on the left endpoint, it is considered to be left of the -- node, and likewise for the right endpoint. --- +-- -- This differentiation is useful for making this function more general: -- When searching in the contiguous nodes of a snippet, we'd like this routine -- to return any of them (obviously the one pos is inside/or on the border of), @@ -231,7 +231,7 @@ local function binarysearch_pos(nodes, pos, respect_rgravs) return nil, 1 end while true do - local mid = left + math.floor((right-left)/2) + local mid = left + math.floor((right - left) / 2) local mid_mark = nodes[mid].mark local mid_from, mid_to = mid_mark:pos_begin_end_raw() diff --git a/lua/luasnip/session/init.lua b/lua/luasnip/session/init.lua index 77447c3ce..52b3b2fbf 100644 --- a/lua/luasnip/session/init.lua +++ b/lua/luasnip/session/init.lua @@ -17,11 +17,11 @@ M.current_nodes = {} -- snippet_roots[n] => list of snippet-roots in buffer n. M.snippet_roots = setmetatable({}, { -- create missing lists automatically. - __index = function(t,k) + __index = function(t, k) local new_t = {} rawset(t, k, new_t) return new_t - end + end, }) M.ns_id = vim.api.nvim_create_namespace("Luasnip") M.active_choice_nodes = {} diff --git a/lua/luasnip/util/util.lua b/lua/luasnip/util/util.lua index d308323d6..7a247210d 100644 --- a/lua/luasnip/util/util.lua +++ b/lua/luasnip/util/util.lua @@ -612,7 +612,7 @@ end -- compare two positions, <0 => pos1 pos1=pos2, >0 => pos1 > pos2. local function pos_cmp(pos1, pos2) -- if row is different it determines result, otherwise the column does. - return 2*cmp(pos1[1], pos2[1]) + cmp(pos1[2], pos2[2]) + return 2 * cmp(pos1[1], pos2[1]) + cmp(pos1[2], pos2[2]) end return {