[Visual Studio Code]: Run task on save
Asked Answered
F

1

9

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.

For answered 10/6, 2020 at 7:21 Comment(0)
S
9

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
  ],
}
Steed answered 17/7, 2022 at 20:0 Comment(3)
I actually don't use VS code anymore, so I'm just gonna accept this answer without testing :S. Thanks for your answer though!For
@For You are welcome and thanks for trusting me :) I saw that this was an old question, but I was looking for the same. When I found the solution, I answered this so you, but also others who find this question on Google can find a solution.Steed
Is this still necessary for running tasks on save? Related #78704458Moo

© 2022 - 2024 — McMap. All rights reserved.