sqlfmt icon indicating copy to clipboard operation
sqlfmt copied to clipboard

Feature: create a VS Code extension to format on save

Open tconbeer opened this issue 2 years ago • 2 comments

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

tconbeer avatar Jan 27 '22 03:01 tconbeer

Currently using the Run on Save extension to do something similar!

rjay98 avatar Apr 20 '22 06:04 rjay98

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}"
            }
        ]
    }
}

ozgenbaris1 avatar Jun 02 '22 11:06 ozgenbaris1

Using Trunk is another option now. See https://docs.sqlfmt.com/integrations/trunk

tconbeer avatar Nov 17 '22 22:11 tconbeer

Also dbt-power-user added support. Closing this, as the other options are all documented at docs.sqlfmt.com

tconbeer avatar Jan 18 '23 23:01 tconbeer