pucelle / vscode-run-on-save

Run configured shell commands when a file is saved in vscode, and output configured messages on status bar.
https://marketplace.visualstudio.com/items?itemName=pucelle.run-on-save
MIT License
51 stars 14 forks source link

commandBeforeSaving leave file unsaved #43

Closed JCKodel closed 2 days ago

JCKodel commented 2 months ago

I have to run two commands before saving on a Dart file: one of them fixes some imports (so it can change the file) and the other sort imports (which also can change the file).

Whenever the files are changed for either commands, the file remain unsaved (if I hit save a second time, as nothing is changed anymore, then VSCode saves the file).

My config:

"runOnSave.statusMessageTimeout": 3000,
"runOnSave.commands": [
  {
    "match": ".*\\.dart$",
    "commandBeforeSaving": "dart-import.fix",
    "runIn": "vscode",
  },
  {
    "match": ".*\\.dart$",
    "commandBeforeSaving": "dartimportsorter.sortImports",
    "runIn": "vscode",
  },
],

Tried with async with no success.

pucelle commented 2 months ago

Thanks for your finding the problem.

I guess, what you met is the default action of vscode, you modify original file, and it becomes unsaved.

The commandBeforeSaving, it was designed for doing something else, like modifying another file. But otherwise, it is very reasonable to call a vscode command before saving, and even modifying source file.

I did some searching, haven't find a solution, but I found may the vscode action (not a plugin action): Format on Save, should exactly fit, but would be more complex to config. image

pucelle commented 6 days ago

Close it, never mind to re-open it.