I am using a language where another extension already provides default folding ranges. I want my extension to add an additional folding range on top of that.
However, I am finding that when I define a folding range provider of my own, it is the only fold provider and the base ones from the other extension are no longer present.
I’ve tried invoking the executeFoldingRangeProvider
to get the original ones, but obviously that invokes my custom folding provider recursively.
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
vscode.languages.registerFoldingRangeProvider(
{ language: 'php', scheme: 'file' },
new CustomFoldingProvider()
)
);
};
// Just returning my custom folding ranges means no other extension's folds get applied
class CustomFoldingProvider implements vscode.FoldingRangeProvider {
async provideFoldingRanges(document: vscode.TextDocument, context: vscode.FoldingContext, token: vscode.CancellationToken): Promise<vscode.FoldingRange[]> {
return getCustomFoldingRanges(document);
}
}
// Trying to get the folding ranges from other providers results in my custom one being invoked recursively, which does not help
class CustomFoldingProvider implements vscode.FoldingRangeProvider {
async provideFoldingRanges(document: vscode.TextDocument, context: vscode.FoldingContext, token: vscode.CancellationToken): Promise<vscode.FoldingRange[]> {
const customRanges = getCustomFoldingRanges(document);
const originalFoldingRanges = await vscode.commands.executeCommand<vscode.FoldingRange[]>('vscode.executeFoldingRangeProvider', document.uri) || [];
return [...originalFoldingRanges, ...customRanges];
}
}
Is there a way to add a folding provider without affecting folds from another extension?