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

Request: Add Command Option to Ignore Save After Delay #5

Closed ragurney closed 3 years ago

ragurney commented 4 years ago

I would like a formatting command to behave as VS Code, and not run if the file is autosaved after a delay, only when I manually save the file. It would be great to have such an option.

pucelle commented 4 years ago

Sorry, I don't have much time these days and can't promise to support this in a short time.

ragurney commented 4 years ago

I could try to look into it if this sounds like a feature you'd accept?

pucelle commented 4 years ago

Can you give more details about your scenario?

ragurney commented 4 years ago

I am currently running a code formatter as the run-on-save command. This is because I couldn't find a way for VS Code to use the google-java-format in their native code formatting. Using native VS Code functionality, I was able to configure code formatting to only run when I explicitly save the file with CMD + S. This was nice because some code formatters will automatically remove unused packages, which is bad if I have a file set to auto-save in one second, and I just added the package and was slow to add code using it. I don't want to turn off this auto-save functionality, so would like to have an option to have run-on-save only trigger when the user saves the file, rather than the system (auto-save) if that's possible.

pucelle commented 4 years ago

Hi, ragurney, As I know, The VSCode plugin could only detect file changes on disk, doesn't distinguish where the saving come from. reference to https://code.visualstudio.com/api/references/vscode-api.

Otherwise, I doubt the "auto save each second", is it really need to? I guess files should be saved to disk only when changed, no need to do so if file was not changed.

So, is there a way for you to improve the "auto save each second"?

BitFis commented 4 years ago

@ragurney what about using custom commands and mapping the formatting command to CTRL+S? This could look like following:

~/.config/Code/User/keybindings.json:

[
    {
        "key": "ctrl+s",
        "command": "workbench.action.tasks.runTask",
        "args": "echo",
        "when": "editorTextFocus"
    }
]

.vscode/tasks.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo", 
            "type": "shell",
            "command": "echo Hello"
        }
    ]
}

This would also enable you to customize the shortcut and giving you even more control. Would this solve your issue?

pucelle commented 3 years ago

Close, never mind to reopen it with any idea.