vscode-code-runner icon indicating copy to clipboard operation
vscode-code-runner copied to clipboard

Can I use Code Runner to "run on save"?

Open leblancexplores opened this issue 7 years ago • 5 comments

leblancexplores avatar Oct 14 '18 04:10 leblancexplores

We have two settings:

  • "code-runner.saveAllFilesBeforeRun": save all files before running
  • "code-runner.saveFileBeforeRun": save the current file before running

Is is enough for your?

formulahendry avatar Nov 01 '18 07:11 formulahendry

@formulahendry I think what the author meant is to run the code every time you save the file. Is this possible?

mb8z avatar Mar 13 '19 13:03 mb8z

As above, I was looking for a solution to this as well; a way to run Code Runner automatically upon saving a file (in contrast to the current implementation of saving file(s) before running Code Runner). This would also bring it closer to Quokka.js which actively updates the output upon saving the watched file.

At the moment, my workaround is to add the following macro/shortcut to VS Code's keybindings.json to simulate this requested behaviour.

{
  "key": "ctrl+enter",
  "command": "code-runner.run"
}

rdhar avatar May 27 '19 16:05 rdhar

This worked well with the multicommand extension. The "clearOutput" is only because my Output doesn't scroll automatically - at least on Windows. All I want is to avoid the mouse during this kind of work session.

[
    {
        "key": "ctrl+r",
        "command": "extension.multiCommand.execute",
        "args": {
            "sequence": [
                "workbench.action.files.save",
                "workbench.output.action.clearOutput",
                "code-runner.run"
            ]
        }
    }
]

hugows avatar Jul 16 '21 09:07 hugows

The following notification pops up when the bash script isn't opened or focused: No code found or selected.

How do I resolve this?

The following is my current settings.json file and I don't know how to make the extension run without having to have my bash script open.

{
	"runOnSave.commands": [{
		"match": ".*",
		"command": "code-runner.run",
                "runIn": "vscode" 
		"runningStatusMessage": "Running ${fileBasename}.",
		"finishStatusMessage": "${fileBasename} completed."


	}],
	"runOnSave.statusMessageTimeout": 78000,
	"files.autoSaveDelay": 1000,
	"code-runner.cwd": "/location/to/bash/script",
	"code-runner.defaultLanguage": "BASH/SH",
	"code-runner.showExecutionMessage": true,
	"code-runner.customCommand": "./bash-script.sh"
}

Run on Save

NorkzYT avatar Jun 22 '22 14:06 NorkzYT