我可以在 vs 代码中为多种语言配置 task.json 文件吗?

我想在 VS Code 中配置一个 tasks.json 文件来运行 python 和 java 代码,只需按下:

  • Ctrl + Shift + B

Python 和 Java 已配置,但需要两个不同的 tasks.json 文件。

但我可以只在 tasks.json 文件夹中保留一个 .vscode 文件。

如何将两个配置文件合并到一个 tasks.json 文件中?

对于 Python:

{
  "version": "2.0.0",
  "tasks": [{
    "label": "Compile and run",
    "type": "shell",
    "command": "",
    "args": [
      "/usr/bin/time",
      "-v",
      "--output",
      "sys.txt",
      "timeout",
      "5",
      "python3",
      "${relativeFile}",
      "<",
      "input.txt",
      ">",
      "output.txt",
    ],
    "group": {
      "kind": "build",
      "isDefault": true
    },
    "problemMatcher": {
      "owner": "py",
      "fileLocation": [
        "relative",
        "${workspaceRoot}"
      ],
      "pattern": {
        "regexp": "^(.*):(d+):(d+):s+(warning|error):s+(.*)$",
        "file": 1,
        "line": 2,
        "column": 3,
        "severity": 4,
        "message": 5
      }
    }
  }],

}

对于 Java:

{
  "version": "2.0.0",
  "tasks": [{
    "label": "Compile and run",
    "type": "shell",
    "command": "",
    "args": [
      "/usr/bin/time",
      "-v",
      "--output",
      "sys.txt",
      "timeout",
      "5",
      "java",
      "${relativeFile}",
      "<",
      "input.txt",
      ">",
      "output.txt",
    ],
    "group": {
      "kind": "build",
      "isDefault": true
    },
    "problemMatcher": {
      "owner": "java",
      "fileLocation": [
        "relative",
        "${workspaceRoot}"
      ],
      "pattern": {
        "regexp": "^(.*):(d+):(d+):s+(warning|error):s+(.*)$",
        "file": 1,
        "line": 2,
        "column": 3,
        "severity": 4,
        "message": 5
      }
    }
  }],
}
stack overflow Can I configure a task.json file for more then one language in vs code?
原文答案

答案:

作者头像

Edit June 2022

I managed to implement this and it’s now available in 1.68 https://code.visualstudio.com/updates/v1_68#_tasks

相关问题