kevinhwang91 / nvim-ufo

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

fold more in Python #91

Closed ipsod closed 1 year ago

ipsod commented 1 year ago

Feature description

In Python code, when everything is folded, more than half of my screen real-estate is taken up by meaningless whitespace and decorator lines (ie: @dataclass - not exactly unimportant, but also not super relevant to browsing/understanding the program's structure).

vim-coiled-snake does Python folding well, but it makes the editor slow (takes several seconds per undo operation, for example), and it obviously lacks most of nvim-ufo's features.

Describe the solution you'd like

See docs and demo for vim-coiled-snake (particularly the first two bullets under A couple features are worth drawing attention to:): https://github.com/kalekundert/vim-coiled-snake

I'd additionally like the ability to hide every blank line that trails a class or function definition. I want to be able to fit more meaningful text on a page, so that there's less scrolling, and because it makes reading and writing coding easier for me.

Additional context

I don't know if this is even inside your wheelhouse, but I hope you can help me find a solution.

kevinhwang91 commented 1 year ago

Please use a treesitter provider:

local ftMap = {
    python = 'treesitter',
}
require('ufo').setup({
    provider_selector = function(bufnr, filetype, buftype)
        return ftMap[filetype]
    end
})

I'd additionally like the ability to hide every blank line that trails a class or function definition.

Look like the treesitter can't help in this way. You must use API to post-handle the folding range by yourself.

If you like the foldexpr of kalekundert/vim-coiled-snake, you can also port the logic into foldingRange. Please refer to ./doc/example.lua