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

Indent fallback not working? #87

Closed nwaywood closed 1 year ago

nwaywood commented 1 year ago

Neovim version (nvim -v | head -n1)

NVIM v0.8.0

Operating system/version

macOS 12.5

How to reproduce the issue

  1. Use this ufo setup from the readme
    
    vim.opt.foldenable = true
    vim.opt.foldlevel = 99
    vim.opt.foldlevelstart = 99

require("ufo").setup({ provider_selector = function(bufnr, filetype, buftype) return { "treesitter", "indent" } end, })


2. Navigate to an indented section of code that doesn't have a treesitter fold
3. Try and fold with `zc`

### Expected behavior

Since no treesitter fold is found, ufo should fallback to indent folding and fold the code by indent 

### Actual behavior

The message `E490: No fold found` is displayed
kevinhwang91 commented 1 year ago

Can't reproduce it, check out your shiftwidth, please.

nwaywood commented 1 year ago

@kevinhwang91 what does shiftwidth need to be set to for the indent fallback to work? Maybe that should be added to the readme?

My shiftwidth is set to 2

kevinhwang91 commented 1 year ago

Maybe that should be added to the readme?

I don't think it's necessary for Vimer, without a correct shiftwidth value, insert a newline is always buggy.

Does the correct shiftwidth work for you?

nwaywood commented 1 year ago

@kevinhwang91 I don't think my shiftwidth value is the issue. I had it set to 2 and it didn't work, I just tried shiftwidth=4 and the bug is present with both values.

Do you have any other ideas what the issue might be?

If I manually set foldmethod=indent then indent based folding works

nwaywood commented 1 year ago

If it's relevant. I am experiencing this bug in a Scala file

kevinhwang91 commented 1 year ago

Make sure that UfoInspect output Selected provider: indent.

Trim the issue file and post it here.

nwaywood commented 1 year ago

@kevinhwang91 oh wait maybe I misunderstood how the fallback works. I am in a file that has some treesitter folds but it isn't able to fold some sections of the file, I thought it is meant to fallback if there is a section of code that treesitter isn't able to fold. Is that not how it works? Does the fallback only work at the file level?

image
kevinhwang91 commented 1 year ago

Does the fallback only work at the file level?

All providers work at the file level. If you want them to work together, you must write an external provider for provider_selector, doc/example may help you understand it.

nwaywood commented 1 year ago

Ah gotcha! Thanks for the help, sorry for my misunderstanding!