mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-19 20:00:07 -04:00
Fold: respect max_fold_level from 'foldnestmax'
This commit is contained in:
parent
f37d94699f
commit
a5360d02e4
1 changed files with 11 additions and 4 deletions
|
|
@ -9,6 +9,7 @@ local M = {}
|
||||||
-- Especially not for every line in the file when `zx` is hit
|
-- Especially not for every line in the file when `zx` is hit
|
||||||
local folds_levels = utils.memoize_by_buf_tick(function(bufnr)
|
local folds_levels = utils.memoize_by_buf_tick(function(bufnr)
|
||||||
local lang = parsers.get_buf_lang(bufnr)
|
local lang = parsers.get_buf_lang(bufnr)
|
||||||
|
local max_fold_level = api.nvim_win_get_option(0, 'foldnestmax')
|
||||||
|
|
||||||
local matches
|
local matches
|
||||||
if query.has_fold(lang) then
|
if query.has_fold(lang) then
|
||||||
|
|
@ -29,7 +30,7 @@ local folds_levels = utils.memoize_by_buf_tick(function(bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- This can be folded
|
-- 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
|
if start ~= stop and not (levels_tmp[start] and levels_tmp[stop]) then
|
||||||
levels_tmp[start] = (levels_tmp[start] or 0) + 1
|
levels_tmp[start] = (levels_tmp[start] or 0) + 1
|
||||||
levels_tmp[stop] = (levels_tmp[stop] or 0) - 1
|
levels_tmp[stop] = (levels_tmp[stop] or 0) - 1
|
||||||
|
|
@ -51,8 +52,14 @@ local folds_levels = utils.memoize_by_buf_tick(function(bufnr)
|
||||||
end
|
end
|
||||||
|
|
||||||
current_level = current_level + shift
|
current_level = current_level + shift
|
||||||
|
|
||||||
|
-- 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)
|
levels[lnum + 1] = prefix .. tostring(current_level)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return levels
|
return levels
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue