Is there a formatter plugin for sql?
i used editor.getAction('editor.action.formatDocument').run(), but it didn't work.
console:
There is no formatter for sql-files installed.
You can add your own formatter using:
monaco.languages.registerDocumentFormattingEditProvider("sql", {
async provideDocumentFormattingEdits(model) {
var formatted = await sqlfmt(model.getValue());
return [
{
range: model.getFullModelRange(),
text: formatted,
},
];
}
});
You still need to implement your own sql formatting though. For a test setup i have installed https://github.com/lopezator/sqlfmt (https://sqlfum.pt/) as a command line tool and made it available through the webserver.
const sqlfmt = (sql) => {
const loc = document.location;
const base = loc.protocol + "//" + loc.host;
const url = base + "/sqlfmt?sql=" + encodeURIComponent(sql);
return fetch(url).then((response) => {
return response.text();
});
};
Most helpful comment
You can add your own formatter using:
You still need to implement your own sql formatting though. For a test setup i have installed https://github.com/lopezator/sqlfmt (https://sqlfum.pt/) as a command line tool and made it available through the webserver.