const vscode = require('vscode'); /** * Macro configuration settings * { [name: string]: { ... Name of the macro * no: number, ... Order of the macro * func: ()=> string | undefined ... Name of the body of the macro function * } * } */ module.exports.macroCommands = { formatLogs: { no: 1, func: formatLogs } }; async function formatLogs() { const editor = vscode.window.activeTextEditor; if (!editor) { // Return an error message if necessary. return 'Editor is not opening.'; } const document = editor.document; // const selection = editor.selection; const text = document.getText(); if (text.length > 0) { const jsonFragmentsArr = text.match(/\{.*\}/g); const jsonText = `[` + jsonFragmentsArr.join(',\n').replace(/""/g, `"`) + `]`; await editor.edit(editBuilder => { const allDocRange = new vscode.Range(document.lineAt(0).range.start, document.lineAt(document.lineCount - 1).range.end); editBuilder.replace(allDocRange, jsonText); }); await vscode.commands.executeCommand('editor.action.formatDocument'); } }