vysker / vscode-php-formatter

Visual Studio Code extension. A wrapper for the Sensiolabs PHP CS Fixer. Analyzes some PHP source code and tries to fix coding standards issues (PSR-1 and PSR-2 compatible).
MIT License
93 stars 11 forks source link

Fix on save? #20

Open nerdo opened 7 years ago

nerdo commented 7 years ago

The docs say that this extension supports fixing a file on save, but doesn't explain how to do that.

I also noticed a commit message saying the onSave command was removed. Is the feature no longer available? Kind of a bummer if that's the case...

fabiolrs commented 6 years ago

Any change anyone has a hint on this?

enriquemorenotent commented 6 years ago

Nothing yet...?

liamdemafelix commented 5 years ago

I installed the macros extension, then on the user settings JSON (settings.json), add the following:

    "macros": {
        "fixOnSave": [
            "phpformatter.fix",
            "workbench.action.files.save"
        ]
    }

Then edit your keybindings. Go to keybindings.json (Preferences > Keyboard Shortcuts) and override the default action of CTRL + S:

{ "key": "ctrl+s", "command": "macros.fixOnSave" }

Note that this only works when you save using CTRL + S, not through other means (or it may, never actually tested, I just assumed that since it runs through the keybinding that it doesn't work anywhere else).

UPDATE: This doesn't work properly. The delay for formatting doesn't overwrite the save state, causing Visual Studio Code to act as if the file isn't saved.