diff options
| author | Markus Koller <markus-koller@gmx.ch> | 2020-09-10 14:18:15 +0200 |
|---|---|---|
| committer | Thomas Vigouroux <tomvig38@gmail.com> | 2020-09-10 15:11:04 +0200 |
| commit | fd6d09fd1f52d0c7d307c7f10b95509400d859c9 (patch) | |
| tree | 95796ab99302a280b405876a0a819dc454b16a33 /lua/nvim-treesitter/utils.lua | |
| parent | 10848ca5bd2893664eab122c9b415860e5352e79 (diff) | |
Find package path based on the Lua source file
This is more robust compared to the previous method where we walked
up the tree and matched on the directory name, which also required
that the repository was cloned in a directory named `nvim-treesitter`.
Diffstat (limited to 'lua/nvim-treesitter/utils.lua')
| -rw-r--r-- | lua/nvim-treesitter/utils.lua | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/lua/nvim-treesitter/utils.lua b/lua/nvim-treesitter/utils.lua index c080c2a9..7a5fbe5e 100644 --- a/lua/nvim-treesitter/utils.lua +++ b/lua/nvim-treesitter/utils.lua @@ -18,14 +18,11 @@ function M.setup_commands(mod, commands) end function M.get_package_path() - for _, path in pairs(api.nvim_list_runtime_paths()) do - local last_segment = vim.fn.fnamemodify(path, ":p:h:t") - if last_segment == "nvim-treesitter" then - return path - end - end + -- Path to this source file, removing the leading '@' + local source = string.sub(debug.getinfo(1, 'S').source, 2) - return nil, 'Plugin runtime path not found.' + -- Path to the package root + return fn.fnamemodify(source, ":p:h:h:h") end function M.get_cache_dir() |
