sqlfmt
sqlfmt copied to clipboard
Feature: create a VS Code extension to format on save
While it's possible to run sqlfmt from the terminal inside VS Code, they support 3rd party formatters via their extensions API, and it would be great if we could support that.
The extension has to be written in Typescript.
There is a scaffold to get started: https://code.visualstudio.com/api/get-started/your-first-extension
As an example of a formatting extension, someone created this for black (before the official python extension added black support): https://github.com/joslarson/black-vscode
Currently using the Run on Save extension to do something similar!
This setting worked for me. Sharing if anyone is interested
{
// settings.json file in vscode
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".*\\.sql",
"isAsync": true,
"cmd": "echo 'I run for ${file}.' && sqlfmt ${file}"
},
{
"match": ".*\\.sql\\.jinja",
"isAsync": true,
"cmd": "echo 'I run for ${file}.' && sqlfmt ${file}"
}
]
}
}
Using Trunk is another option now. See https://docs.sqlfmt.com/integrations/trunk
Also dbt-power-user added support. Closing this, as the other options are all documented at docs.sqlfmt.com