Home > Blockchain >  How can I trigger a command palette action from a task?
How can I trigger a command palette action from a task?

Time:05-24

I have this task I've created:

{
  "label": "Regen Coverage",
  "type": "shell",
  "group": "test",
  "presentation": {
      "reveal": "always",
      "panel": "dedicated"
  },
  "command": [
    "go test ./internal/... --tags=dynamic,integration -coverpkg=./... -count=1 -coverprofile ./cover.out",
    "gcov2lcov -infile=cover.out -outfile=cover.lcov",
  ]
}

I'd like to trigger a command palette action from an extension (the command is Coverage Gutters: Watch. I think this should be possible, based on this ticket: https://github.com/microsoft/vscode/issues/11396, but I have no idea what the command would be called, and the docs say that a command must return a string. Any ideas?

CodePudding user response:

Thank you to @rioV8 I was able to find the commandID from the key binding GUI. This is the resulting task setup:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
      {
        "label": "run integration tests and cover",
        "type": "shell",
        "group": "test",
        "presentation": {
          "reveal": "always",
          "panel": "shared"
        },
        "command": [
          "go test ./internal/... --tags=dynamic,integration -coverpkg=./... -count=1 -coverprofile ./cover.out",
          "gcov2lcov -infile=cover.out -outfile=cover.lcov"
        ]
      },
      {
        "label": "Regen and Watch Coverage",
        "dependsOn": [
          "run integration tests and cover"
        ],
        "presentation": {
          "reveal": "always",
          "panel": "shared"
        },
        "command": [
          "${command:coverage-gutters.watchCoverageAndVisibleEditors}"
        ],
        "problemMatcher": []
      }
    ]
}
  • Related