diff options
| author | Nat Williams <nat.williams@kin.com> | 2023-02-02 13:16:44 -0600 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2023-02-24 14:55:30 -0800 |
| commit | 3fab7abf6f653eb92eee74c19ce5e655536ced87 (patch) | |
| tree | 525eb1f17c80bbd8d65c2ae900a9f1e69e91557b | |
| parent | update docs for transform_fn (diff) | |
| download | nvim-treesitter-3fab7abf6f653eb92eee74c19ce5e655536ced87.tar nvim-treesitter-3fab7abf6f653eb92eee74c19ce5e655536ced87.tar.gz nvim-treesitter-3fab7abf6f653eb92eee74c19ce5e655536ced87.tar.bz2 nvim-treesitter-3fab7abf6f653eb92eee74c19ce5e655536ced87.tar.lz nvim-treesitter-3fab7abf6f653eb92eee74c19ce5e655536ced87.tar.xz nvim-treesitter-3fab7abf6f653eb92eee74c19ce5e655536ced87.tar.zst nvim-treesitter-3fab7abf6f653eb92eee74c19ce5e655536ced87.zip | |
add statusline option to dedupe or not
| -rw-r--r-- | doc/nvim-treesitter.txt | 4 | ||||
| -rw-r--r-- | lua/nvim-treesitter/statusline.lua | 10 |
2 files changed, 11 insertions, 3 deletions
diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt index f2da04203..f8ac369bd 100644 --- a/doc/nvim-treesitter.txt +++ b/doc/nvim-treesitter.txt @@ -446,7 +446,8 @@ Default options (lua syntax): indicator_size = 100, type_patterns = {'class', 'function', 'method'}, transform_fn = function(line, _node) return line:gsub('%s*[%[%(%{]*%s*$', '') end, - separator = ' -> ' + separator = ' -> ', + dedupe = true } < - `indicator_size` - How long should the string be. If longer, it is cut from @@ -456,6 +457,7 @@ Default options (lua syntax): default removes opening brackets and spaces from end. Takes two arguments: the text of the line in question, and the corresponding treesitter node. - `separator` - Separator between nodes. +- `dedupe` - Whether or not to remove duplicate components. *nvim_treesitter#foldexpr()* nvim_treesitter#foldexpr()~ diff --git a/lua/nvim-treesitter/statusline.lua b/lua/nvim-treesitter/statusline.lua index cd75fcb00..fde7def2b 100644 --- a/lua/nvim-treesitter/statusline.lua +++ b/lua/nvim-treesitter/statusline.lua @@ -21,6 +21,10 @@ function M.statusline(opts) local type_patterns = options.type_patterns or { "class", "function", "method" } local transform_fn = options.transform_fn or transform_line local separator = options.separator or " -> " + local dedupe = options.dedupe + if dedupe == nil then + dedupe = true + end local current_node = ts_utils.get_node_at_cursor() if not current_node then @@ -32,8 +36,10 @@ function M.statusline(opts) while expr do local line = ts_utils._get_line_for_node(expr, type_patterns, transform_fn, bufnr) - if line ~= "" and not vim.tbl_contains(lines, line) then - table.insert(lines, 1, line) + if line ~= "" then + if not dedupe or not vim.tbl_contains(lines, line) then + table.insert(lines, 1, line) + end end expr = expr:parent() end |
