diff options
| author | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2022-04-19 08:50:47 +0200 |
|---|---|---|
| committer | Ariel D'Alessandro <dalessandro.ariel@gmail.com> | 2022-04-19 08:50:47 +0200 |
| commit | d202cdf85864d5392c3c476727390c01f43e38bb (patch) | |
| tree | 06efee634998c891aabc49838ab860345fb5aa3a /lua/alpha/utils.lua | |
| parent | c6b764395fc444f33998fd47300c585e0e9221e3 (diff) | |
| download | nvim-conf-d202cdf85864d5392c3c476727390c01f43e38bb.tar.gz nvim-conf-d202cdf85864d5392c3c476727390c01f43e38bb.zip | |
Update the null ls to move the refactor there
Diffstat (limited to 'lua/alpha/utils.lua')
| -rw-r--r-- | lua/alpha/utils.lua | 41 |
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 |