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
50 stars 11 forks source link

Add an Option to Only Run On Manual Save #40

Closed DavidArchibald closed 5 months ago

DavidArchibald commented 5 months ago

I've found that if the command in question modifies the file I can get some annoying "Failed to save xyz: The content of the file is newer. [...]" errors when it triggers off of auto saves. This happens with async: false too so this is probably because the did save events don't expect modifications.

I'm sure the same issue technically exists during a manual save as well but it'd require saving and then very quickly editing which is unrealistic compared to an auto save. In addition it's a better user experience in some cases to only run on manual save.

Resolves #5 which @ragurney might be pleased to know, even if 4 years late.

pucelle commented 5 months ago

Will check this soon.

pucelle commented 5 months ago

Already released v1.8.0 to include your codes. I made a little change, welcome to check it.

DavidArchibald commented 5 months ago

Thanks!

lonix1 commented 3 months ago

@DavidArchibald Just upgraded to latest version and was curious about this feature you added.

I understand what you mean by a manual save - "ctrl s".

But what then is the alternative? What do you mean by an automatic / non-manual save? When does that happen?

DavidArchibald commented 3 months ago

@lonix1 if you have files.autoSave set then the file will be saved automatically under whatever condition you set which would inevitably cause the run on save extension to trigger.

This can be annoying if, for example, you have it set to format a type of file (this is useful if it doesn't have an LSP yet) as if you simply pause for a bit (at least if you use afterDelay) then the file will be reformatted. Even worse, if you pause just long enough to kick off the task and then continue editing then it's quite likely that VSCode will complain about conflicting versions of the file as there's the version you edited and the version that the run-on-save task edited it to be.

Only running on manual save technically doesn't remove that race condition but in practice I'm pressing ctrl+s whenever I want formatting/linting to update because that's how many extensions work; they only run on manual save and so I expect to wait. By comparison I don't want to have to prolong any small pauses I make during typing just to make sure that the run-on-save task completes successfully.

lonix1 commented 3 months ago

Thanks for the thorough explanation!