VS CODE SaveAll from Task

Viewed 169

I want to execute SaveAll from a task such as evoking workbench.action.files.saveAll from within Task.

The objective is to make sure all files are saved before triggering series of other Tasks.

  • Task #1: SaveAll (workbench.action.files.saveAll)
  • Task #2: Run Grunt that dependsOn Task#1

The tasks.json looks something like this

{   
    "version": "2.0.0",     
    "tasks": [
        {
             "command": "workbench.action.files.saveAll",
             "label": "SaveAllFiles",
         },
 
         {    
            "type": "grunt",            
             "task": "default",             
              "label": "Execute Grunt",
 
             "dependsOn": [
                 "SaveAllFiles"
             ],
             "problemMatcher": []
        }
   ] 
}

In theory, all I should have to do is execute the task labeled Execute Grunt, and it will call the SaveAllFiles task. To be precise, I don't want to trigger tasks based on Save or SaveAll events; there are times when I want to save files, but not trigger other tasks.

1 Answers
{
  "label": "SaveAllFiles",
  "command": "${command:workbench.action.files.saveAll}",
  "type": "shell",
  "problemMatcher": []
},

{    
  "type": "grunt",            
  "task": "default",             
  "label": "Execute Grunt",
 
  "dependsOn": [
    "SaveAllFiles"
  ],
  "dependsOrder": "sequence",   // need this, "parallel" is the default otherwise
  "problemMatcher": []
}

${command:workbench.action.files.saveAll} is the general form for calling a vscode command, you can also call extension or macro commands this way.

The info on this is in https://code.visualstudio.com/docs/editor/variables-reference#_command-variables which makes it a little tricky to find as it isn't in the Tasks documentation.

Related