diff options
Diffstat (limited to 'lua/nvim-treesitter/utils.lua')
| -rw-r--r-- | lua/nvim-treesitter/utils.lua | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lua/nvim-treesitter/utils.lua b/lua/nvim-treesitter/utils.lua index 6fa15981..41833f8c 100644 --- a/lua/nvim-treesitter/utils.lua +++ b/lua/nvim-treesitter/utils.lua @@ -45,4 +45,21 @@ function M.get_cache_dir() return nil, 'Invalid cache rights, $XDG_CACHE_HOME or /tmp should be read/write' end +--- Gets a property at path +-- @param tbl the table to access +-- @param path the '.' seperated path +-- @returns the value at path or nil +function M.get_at_path(tbl, path) + local segments = vim.split(path, '.', true) + local result = tbl + + for _, segment in ipairs(segments) do + if type(result) == 'table' then + result = result[segment] + end + end + + return result +end + return M |
