diff options
| author | Thomas Vigouroux <tomvig38@gmail.com> | 2020-08-28 17:41:27 +0200 |
|---|---|---|
| committer | Thomas Vigouroux <tomvig38@gmail.com> | 2020-09-01 21:51:17 +0200 |
| commit | 03621e758c640b2ec20d32221d2e28ef0fd359e6 (patch) | |
| tree | 7308695610e9039cac43d3d87a547fa473d2691f /lua | |
| parent | fold(c): ignore compound statements (diff) | |
| download | nvim-treesitter-03621e758c640b2ec20d32221d2e28ef0fd359e6.tar nvim-treesitter-03621e758c640b2ec20d32221d2e28ef0fd359e6.tar.gz nvim-treesitter-03621e758c640b2ec20d32221d2e28ef0fd359e6.tar.bz2 nvim-treesitter-03621e758c640b2ec20d32221d2e28ef0fd359e6.tar.lz nvim-treesitter-03621e758c640b2ec20d32221d2e28ef0fd359e6.tar.xz nvim-treesitter-03621e758c640b2ec20d32221d2e28ef0fd359e6.tar.zst nvim-treesitter-03621e758c640b2ec20d32221d2e28ef0fd359e6.zip | |
docs(fold): document and comment
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/fold.lua | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/lua/nvim-treesitter/fold.lua b/lua/nvim-treesitter/fold.lua index 0bfe0f7cc..9f83f8c30 100644 --- a/lua/nvim-treesitter/fold.lua +++ b/lua/nvim-treesitter/fold.lua @@ -5,6 +5,8 @@ local parsers = require'nvim-treesitter.parsers' local M = {} +-- This is cached on buf tick to avoid computing that multiple times +-- 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) @@ -38,10 +40,12 @@ local folds_levels = utils.memoize_by_buf_tick(function(bufnr) local levels = {} 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= '' local shift = levels_tmp[lnum] or 0 + -- Determine if it's the start of a fold if levels_tmp[lnum] and shift >= 0 then prefix = '>' end |
