import { FoldingController, setCollapseStateForMatchingLines } from 'vscode/monaco';

function setup(editor) {
    editor.addAction({
        id: 'editor.foldAllAutofoldRegions',
        label: 'Fold all autofold regions',
        run: async (editor) => {
            const foldingController = FoldingController.get(editor);
            const foldingModelPromise = foldingController?.getFoldingModel();
            if (foldingModelPromise != null) {
                return foldingModelPromise.then(foldingModel => {
                    const editorModel = editor.getModel();
                    if (editorModel == null || foldingModel == null) {
                        return;
                    }
                    const regExp = /.*autofold.*/;
                    setCollapseStateForMatchingLines(foldingModel, regExp, true);
                });
            }
        }
    });
}

export { setup as default };
