diff options
| author | Thomas Vigouroux <tomvig38@gmail.com> | 2020-05-05 15:04:01 +0200 |
|---|---|---|
| committer | Thomas Vigouroux <tomvig38@gmail.com> | 2020-05-05 20:06:45 +0200 |
| commit | 7682a1a49f7c3be58df18dfc18ad3ba65dd3be1f (patch) | |
| tree | e3534fa1b90b4769baff692dfbd1d6239e0b5a1a /lua/nvim-treesitter.lua | |
| parent | Merge pull request #37 from theHamsta/node-movement (diff) | |
| download | nvim-treesitter-7682a1a49f7c3be58df18dfc18ad3ba65dd3be1f.tar nvim-treesitter-7682a1a49f7c3be58df18dfc18ad3ba65dd3be1f.tar.gz nvim-treesitter-7682a1a49f7c3be58df18dfc18ad3ba65dd3be1f.tar.bz2 nvim-treesitter-7682a1a49f7c3be58df18dfc18ad3ba65dd3be1f.tar.lz nvim-treesitter-7682a1a49f7c3be58df18dfc18ad3ba65dd3be1f.tar.xz nvim-treesitter-7682a1a49f7c3be58df18dfc18ad3ba65dd3be1f.tar.zst nvim-treesitter-7682a1a49f7c3be58df18dfc18ad3ba65dd3be1f.zip | |
feat: provide a statusline indicator
It will show the current branch at the cursor going the tree as such.
root->node->subnode->leaf
If an argument is provided to `statusline`, then the tree will be
truncated as follows :
..->subnode->subnode
Diffstat (limited to 'lua/nvim-treesitter.lua')
| -rw-r--r-- | lua/nvim-treesitter.lua | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lua/nvim-treesitter.lua b/lua/nvim-treesitter.lua index e1c95ed31..90b5468a3 100644 --- a/lua/nvim-treesitter.lua +++ b/lua/nvim-treesitter.lua @@ -24,4 +24,35 @@ function M.setup(lang) end end +function M.statusline(indicator_size) + local indicator_size = indicator_size or 1000 + local expr = require"nvim-treesitter.utils".expression_at_point() + local current_node = + require'nvim-treesitter.node_movement'.current_node[api.nvim_get_current_buf()] + + local indicator = "" + while expr and (#indicator + #(expr:type()) + 5) < indicator_size do + + local prefix = "" + if expr:parent() then + prefix = "->" + end + + + if expr == current_node then + indicator = string.format("%s[%s]%s", prefix, expr:type(), indicator) + else + indicator = prefix .. expr:type() .. indicator + end + + expr = expr:parent() + end + + if expr then + return "..." .. indicator + else + return indicator + end +end + return M |
