kevinhwang91 / nvim-ufo

Not UFO in the sky, but an ultra fold in Neovim.
BSD 3-Clause "New" or "Revised" License
2.16k stars 37 forks source link

Ignore empty lines on fold, like treesitter #169

Closed yochem closed 8 months ago

yochem commented 8 months ago

Neovim version (nvim -v | head -n1)

NVIM v0.10.0-dev-743+g9b5f58185-Homebrew

Operating system/version

MacOS 14.0

How to reproduce the issue

  1. Use the following config for nvim-ufo (via lazy.nvim):
    return {
    'kevinhwang91/nvim-ufo',
    init = function ()
        vim.keymap.set('n', 'zR', function ()
            require('ufo').openAllFolds()
        end)
        vim.keymap.set('n', 'zR', function ()
            require('ufo').closeAllFolds()
        end)
    end,
    opts = {
        provider_selector = function(bufnr, filetype, buftype)
            return {'treesitter', 'indent'}
        end
    },
    dependencies = {
        'kevinhwang91/promise-async'
    },
    event = "BufReadPost",
    }
  2. Open markdown file and add something like this:
    
    # test

test

new header

3. Move cursor to line under `# test` and fold (e.g. with `zc`)
4. Notice it includes the empty lines. `nvim-treesitter` does *not* do this. It trims these emtpy lines from the region [here](https://github.com/nvim-treesitter/nvim-treesitter/blob/master/queries/markdown/folds.scm#L8).

### Expected behavior

```markdown
# test...

# new header

Expect it to use treesitter to get its folds, and thus exclude empty lines from fold. This behaviour can be seen by disabling nvim-ufo (in the lazy.nvim config above, add enabled = false). Restart nvim and run: set foldmethod=expr foldexpr=nvim_treesitter#foldexpr(). This should exclude the empty lines in the fold.

Actual behavior

# test...
# new header

It includes the empty lines in the fold.

yochem commented 8 months ago

You're awesome! Thank you so much 🙏🏼