Support for FoldingRangeProviders that don't disable indentation based folding
#265 661 ouverte le 8 sept. 2025
Métriques du dépôt
- Stars
- (74 848 stars)
- Métriques de merge PR
- (Merge moyen 11h 43m) (1 000 PRs mergées en 30 j)
Description
VS Codes folding in auto mode works by using the folding range provider if one is provided and falling back to an indentation model if not.
If there are multiple folding range providers, then they seems to work together.
As such it is possible (providing you avoid range start conflicts) to offer a second folding provider for some specific functionality (eg you might have some set of specific region comments which are not language specific that you want to add to a few languages via an extension).
The issue comes when one of those languages does not provider a folding range provider and instead uses the indentation based folding.
Eg, support you have typescript which provides a folding range provider as part of the language server and c which doesn't (made up examples - pretty sure they both do).
If you define a custom folding range provider, that says it works on typescript and c, the result is that in typescript your folding ranges are added to the existing ones, but in c, they replace them entirely.
Essentially, the behaviour of your extension differs dramatically based on the other extensions that the user has installed.
So the options currently are.
- Only offer your folding range provider for languages which already offer one by default.
- Either add a custom folding range provider to your extension or depend on another extension that does.
- Add to the documentation of your extension an instruction to install a folding range provider for the language if the user doesn't have one already.
The issue with 1 is that it limits how much your extension can offer. With 2 that if the user already has a folding range provider for the default folding,your provider might conflict with that, and with 3 that no one reads the documentation so you are likely to just break base folding for most users.
My proposal would be that we allow a flag on the folding range provider, eg disablesIndentation?: boolean. If this is true | undefined, then we do the current behaviour where we disable the indentation based folding and only use the new provider (making this change a no-op for existing extensions). If this is set to false, then we do not disable the indentation folding and use the ranges provided by both the extension, and the indentation model.
In the event of multiple folding ranges being provided for a language provider, then we would keep indentation iff disablesIndentation === false for all providers. A single provider replacing indentation should be enough.
Slightly related: https://stackoverflow.com/questions/70090367/how-to-use-indentation-folding-strategy-and-custom-folding-rules