Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[Visual Studio Code]: Run task on save

I want do develop C programs with vscode.

My tasks.json, which describes the build stage if I understood that correctly, looks like this:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: gcc build active file",
            "command": "/usr/bin/gcc",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "runOptions": {
                "runOn": "default"
            }
        }
    ]
}

Since all the compiler errors are generated by the build, I would like to run it every time I save the file. This allows me to get immediate compiler feedback.

How can I set this up this? Note that most Plugins like Run on Save don't work, since I can't specify the task, just the command, and then I won't get the compiler errors.

like image 559
TobTobXX Avatar asked Feb 12 '26 04:02

TobTobXX


1 Answers

You can use the Trigger Task on Save extension.

To set it up, add the following to your .vscode/settings.json:

"triggerTaskOnSave.tasks": {
  "C/C++: gcc build active file": [
    "*", // <-- Glob pattern to specify which files should trigger the task
  ],
}
like image 108
FZs Avatar answered Feb 14 '26 11:02

FZs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!