diff options
| author | Santos Gallegos <stsewd@protonmail.com> | 2020-09-04 23:05:18 -0500 |
|---|---|---|
| committer | Thomas Vigouroux <tomvig38@gmail.com> | 2020-09-07 18:24:21 +0200 |
| commit | a5360d02e4d3fddd86e8f0552bf7017b85c54737 (patch) | |
| tree | 2d41ae8cbcf6dd74edf2262dacbc543a76aac7c4 /lua | |
| parent | go locals: remove unused strip! directive (diff) | |
| download | nvim-treesitter-a5360d02e4d3fddd86e8f0552bf7017b85c54737.tar nvim-treesitter-a5360d02e4d3fddd86e8f0552bf7017b85c54737.tar.gz nvim-treesitter-a5360d02e4d3fddd86e8f0552bf7017b85c54737.tar.bz2 nvim-treesitter-a5360d02e4d3fddd86e8f0552bf7017b85c54737.tar.lz nvim-treesitter-a5360d02e4d3fddd86e8f0552bf7017b85c54737.tar.xz nvim-treesitter-a5360d02e4d3fddd86e8f0552bf7017b85c54737.tar.zst nvim-treesitter-a5360d02e4d3fddd86e8f0552bf7017b85c54737.zip | |
Fold: respect max_fold_level from 'foldnestmax'
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/fold.lua | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lua/nvim-treesitter/fold.lua b/lua/nvim-treesitter/fold.lua index 9f83f8c30..30ae288fb 100644 --- a/lua/nvim-treesitter/fold.lua +++ b/lua/nvim-treesitter/fold.lua @@ -9,6 +9,7 @@ local M = {} -- Especially not for every line in the file when `zx` is hit local folds_levels = utils.memoize_by_buf_tick(function(bufnr) local lang = parsers.get_buf_lang(bufnr) + local max_fold_level = api.nvim_win_get_option(0, 'foldnestmax') local matches if query.has_fold(lang) then @@ -29,7 +30,7 @@ local folds_levels = utils.memoize_by_buf_tick(function(bufnr) end -- This can be folded - -- Fold only multiline nodes that are not exactly the same as prevsiously met folds + -- Fold only multiline nodes that are not exactly the same as previously met folds if start ~= stop and not (levels_tmp[start] and levels_tmp[stop]) then levels_tmp[start] = (levels_tmp[start] or 0) + 1 levels_tmp[stop] = (levels_tmp[stop] or 0) - 1 @@ -41,8 +42,8 @@ local folds_levels = utils.memoize_by_buf_tick(function(bufnr) local current_level = 0 -- We now have the list of fold opening and closing, fill the gaps and mark where fold start - for lnum=0,api.nvim_buf_line_count(bufnr) do - local prefix= '' + for lnum=0, api.nvim_buf_line_count(bufnr) do + local prefix = '' local shift = levels_tmp[lnum] or 0 -- Determine if it's the start of a fold @@ -51,7 +52,13 @@ local folds_levels = utils.memoize_by_buf_tick(function(bufnr) end current_level = current_level + shift - levels[lnum + 1] = prefix .. tostring(current_level) + + -- Ignore folds greater than max_fold_level + if current_level > max_fold_level then + levels[lnum + 1] = max_fold_level + else + levels[lnum + 1] = prefix .. tostring(current_level) + end end return levels |
