aboutsummaryrefslogtreecommitdiffstats
path: root/lua/alpha/utils.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/alpha/utils.lua')
-rw-r--r--lua/alpha/utils.lua41
1 files changed, 41 insertions, 0 deletions
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