From d202cdf85864d5392c3c476727390c01f43e38bb Mon Sep 17 00:00:00 2001 From: Ariel D'Alessandro Date: Tue, 19 Apr 2022 08:50:47 +0200 Subject: Update the null ls to move the refactor there --- lua/alpha/utils.lua | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 lua/alpha/utils.lua (limited to 'lua/alpha/utils.lua') diff --git a/lua/alpha/utils.lua b/lua/alpha/utils.lua new file mode 100644 index 0000000..f1de150 --- /dev/null +++ b/lua/alpha/utils.lua @@ -0,0 +1,41 @@ +local ts_utils = require("nvim-treesitter.ts_utils") + +local M = {} + +M.ucfirst = function(str) + return (str:gsub("^%l", string.upper)) +end + +M.get_master_node = function() + local node = ts_utils.get_node_at_cursor() + if node == nil then + error("No treesitter parser found.") + end + + local start_row = node:start() + + local parent = node:parent() + while (parent ~= nil and parent:start() == start_row) do + node = parent + parent = node:parent() + end + + return node +end + +M.get_root_node = function () + local node = ts_utils.get_node_at_cursor() + if node == nil then + error("No treesitter parser found.") + end + + local parent = node:parent() + while (parent ~= nil) do + node = parent + parent = node:parent() + end + + return node +end + +return M -- cgit v1.2.3