From 767169cc43ab362167b9cbf535d3d6edb684bbc8 Mon Sep 17 00:00:00 2001 From: danymat Date: Tue, 8 Feb 2022 15:50:36 +0100 Subject: [PATCH] chore: stylua formatting --- lua/neogen/config.lua | 4 ++-- lua/neogen/configurations/lua.lua | 2 +- lua/neogen/generator.lua | 9 ++++----- lua/neogen/mark.lua | 11 +++++------ lua/neogen/utilities/helpers.lua | 7 +++---- lua/neogen/utilities/nodes.lua | 17 +++++++++-------- 6 files changed, 24 insertions(+), 26 deletions(-) diff --git a/lua/neogen/config.lua b/lua/neogen/config.lua index 62e9ac4..efe745b 100644 --- a/lua/neogen/config.lua +++ b/lua/neogen/config.lua @@ -1,4 +1,4 @@ -local config = {_data = {}} +local config = { _data = {} } config.get = function() return config._data @@ -14,7 +14,7 @@ config.setup = function(default, user) end rawset(langs, ft, ft_config) return ft_config - end + end, }) config._data = data return data diff --git a/lua/neogen/configurations/lua.lua b/lua/neogen/configurations/lua.lua index d04adcb..55d77b3 100644 --- a/lua/neogen/configurations/lua.lua +++ b/lua/neogen/configurations/lua.lua @@ -69,7 +69,7 @@ end return { -- Search for these nodes parent = { - func = { "function_declaration", "assignment_statement", "variable_declaration", "field"}, + func = { "function_declaration", "assignment_statement", "variable_declaration", "field" }, class = { "local_variable_declaration", "variable_declaration" }, type = { "local_variable_declaration", "variable_declaration" }, file = { "chunk" }, diff --git a/lua/neogen/generator.lua b/lua/neogen/generator.lua index 1ec1706..1ec9084 100644 --- a/lua/neogen/generator.lua +++ b/lua/neogen/generator.lua @@ -22,7 +22,7 @@ local function get_parent_node(filetype, typ, language) language.locator = language.locator or default_locator -- Use the language locator to locate one of the required parent nodes above the cursor - return language.locator({root = tree, current = ts_utils.get_node_at_cursor(0)}, language.parent[typ]) + return language.locator({ root = tree, current = ts_utils.get_node_at_cursor(0) }, language.parent[typ]) end --- Generates the prefix according to `template` options. @@ -201,7 +201,7 @@ return setmetatable({}, { table.insert(sects, line:sub(last_col + 1, s - 1)) if input_after_comment then len = len + s - last_col - 1 - table.insert(marks_pos, {row + r - 1, len - 1}) + table.insert(marks_pos, { row + r - 1, len - 1 }) end last_col = e end @@ -220,8 +220,7 @@ return setmetatable({}, { vim.cmd("startinsert") mark:jump() -- Add range mark after first jump - mark:add_range_mark({row, 0, row + #template_content, 1}) + mark:add_range_mark({ row, 0, row + #template_content, 1 }) end - end + end, }) - diff --git a/lua/neogen/mark.lua b/lua/neogen/mark.lua index ab02013..b4ea8d8 100644 --- a/lua/neogen/mark.lua +++ b/lua/neogen/mark.lua @@ -63,15 +63,14 @@ mark.mark_len = function(self) end mark.get_range_mark = function(self) - local d = api.nvim_buf_get_extmark_by_id(self.bufnr, ns, self.range_id, {details = true}) + local d = api.nvim_buf_get_extmark_by_id(self.bufnr, ns, self.range_id, { details = true }) local row, col, end_row, end_col = d[1], d[2], d[3].end_row, d[3].end_col return row, col, end_row, end_col end mark.add_range_mark = function(self, range) local row, col, end_row, end_col = unpack(range) - self.range_id = api.nvim_buf_set_extmark(self.bufnr, ns, row, col, - {end_row = end_row, end_col = end_col}) + self.range_id = api.nvim_buf_set_extmark(self.bufnr, ns, row, col, { end_row = end_row, end_col = end_col }) end mark.cursor_in_range = function(self, validated) @@ -80,7 +79,7 @@ mark.cursor_in_range = function(self, validated) local pos = api.nvim_win_get_cursor(self.winid) pos[1] = pos[1] - 1 local row, col, end_row, end_col = self:get_range_mark() - ret = compare_pos({row, col}, pos) <= 0 and compare_pos({end_row, end_col}, pos) >= 0 + ret = compare_pos({ row, col }, pos) <= 0 and compare_pos({ end_row, end_col }, pos) >= 0 end return ret end @@ -124,7 +123,7 @@ mark.jump = function(self, reverse) end if mark:jumpable(reverse) then local line, row = unpack(self:get_mark(self.index)) - api.nvim_win_set_cursor(self.winid, {line + 1, row}) + api.nvim_win_set_cursor(self.winid, { line + 1, row }) end end @@ -133,7 +132,7 @@ mark.jump_last_cursor = function(self, validated) local winid = self.winid local pos = api.nvim_buf_get_extmark_by_id(self.bufnr, ns, self.last_cursor_id, {}) local line, col = unpack(pos) - api.nvim_win_set_cursor(winid, {line + 1, col}) + api.nvim_win_set_cursor(winid, { line + 1, col }) end end diff --git a/lua/neogen/utilities/helpers.lua b/lua/neogen/utilities/helpers.lua index 5a66fb0..f35f516 100644 --- a/lua/neogen/utilities/helpers.lua +++ b/lua/neogen/utilities/helpers.lua @@ -1,7 +1,7 @@ local config = require("neogen.config") return { notify = function(msg, log_level) - vim.notify(msg, log_level, {title = "Neogen"}) + vim.notify(msg, log_level, { title = "Neogen" }) end, --- Generates a list of possible types in the current language @@ -20,7 +20,6 @@ return { return vim.tbl_keys(language.parent) end, split = function(s, sep, plain) - return vim.fn.has("nvim-0.6") == 1 and vim.split(s, sep, {plain = plain}) or - vim.split(s, sep, plain) - end + return vim.fn.has("nvim-0.6") == 1 and vim.split(s, sep, { plain = plain }) or vim.split(s, sep, plain) + end, } diff --git a/lua/neogen/utilities/nodes.lua b/lua/neogen/utilities/nodes.lua index 448eb02..1f41620 100644 --- a/lua/neogen/utilities/nodes.lua +++ b/lua/neogen/utilities/nodes.lua @@ -46,7 +46,7 @@ return { break end - self:recursive_find(child, node_name, {results = results}) + self:recursive_find(child, node_name, { results = results }) end return results @@ -63,22 +63,23 @@ return { result = result or {} for _, subtree in pairs(tree) do - assert(not subtree.retrieve or vim.tbl_contains({"all", "first"}, subtree.retrieve), - "Supported nodes matching: all|first") + assert( + not subtree.retrieve or vim.tbl_contains({ "all", "first" }, subtree.retrieve), + "Supported nodes matching: all|first" + ) -- Match all child nodes of the parent node local matched = self:matching_child_nodes(parent, subtree.node_type) -- Only keep the node with custom position if not subtree.retrieve then - assert(type(subtree.position) == "number", - "please require position if retrieve is nil") - matched = {matched[subtree.position]} + assert(type(subtree.position) == "number", "please require position if retrieve is nil") + matched = { matched[subtree.position] } end if subtree.recursive then local first = subtree.retrieve == "first" - matched = self:recursive_find(parent, subtree.node_type, {first = first}) + matched = self:recursive_find(parent, subtree.node_type, { first = first }) end for _, child in pairs(matched) do @@ -94,5 +95,5 @@ return { end end return result - end + end, }