diff options
| author | Lewis Russell <lewis6991@gmail.com> | 2022-04-21 10:48:47 +0100 |
|---|---|---|
| committer | Lewis Russell <me@lewisr.dev> | 2022-09-12 11:49:51 +0100 |
| commit | 2eaf18826988f921ddb39e4a2e7d23d95bb0e52a (patch) | |
| tree | 4d4d76fd369b82f7a0ab26725f9c24cef13e6250 /lua/nvim-treesitter/fold.lua | |
| parent | 2bc82e814bbe25eb4b69e6d002c0e55573d726d4 (diff) | |
fix(fold): don't include whitespace end regions
Some languages that are difficult to parse via Treesitter may
incorrectly include whitespace lines at the end of regions. This can
makes the calculated folds sub-optimal.
To recitfy, use a custom directive (trim), to calculate the range with
the trailing whitespace lines removed. Note this only works if the
region end column is 0.
Also added folds for Make.
Diffstat (limited to 'lua/nvim-treesitter/fold.lua')
| -rw-r--r-- | lua/nvim-treesitter/fold.lua | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lua/nvim-treesitter/fold.lua b/lua/nvim-treesitter/fold.lua index 01a7c08e..1f417414 100644 --- a/lua/nvim-treesitter/fold.lua +++ b/lua/nvim-treesitter/fold.lua @@ -39,8 +39,13 @@ local folds_levels = tsutils.memoize_by_buf_tick(function(bufnr) local min_fold_lines = api.nvim_win_get_option(0, "foldminlines") - for _, node in ipairs(matches) do - local start, _, stop, stop_col = node.node:range() + for _, match in ipairs(matches) do + local start, stop, stop_col + if match.metadata and match.metadata.range then + start, _, stop, stop_col = unpack(match.metadata.range) + else + start, _, stop, stop_col = match.node:range() + end if stop_col == 0 then stop = stop - 1 |
