Build currently opened file in Visual Studio Code

前端 未结 2 502
梦谈多话
梦谈多话 2021-01-18 14:09

I have a workspace that I use for smaller test programs I write to practice concepts. Hence, in VS Code, I have a build task for each file in the folder.

By default,

相关标签:
2条回答
  • 2021-01-18 14:40

    To Build on Rob's Answer, you can also set a shortcut key combination to trigger each task by adding to keybindings.json, e.g.

    {
        "key": "ctrl+h",
        "command": "workbench.action.tasks.runTask",
        "args": "Run tests"
    }
    

    where the args component is replaced with the task name.

    You could use this in combination with ${file} in tasks.json to differentiate between the separate build types.

    e.g. hit Ctrl+h for python and Ctrl+Shift+h for tsc

    0 讨论(0)
  • 2021-01-18 14:42

    You can use the ${file} wildcard to pass the current file to your build program/script.

    There's an example given in the docs for TS: https://code.visualstudio.com/Docs/editor/tasks#_operating-system-specific-properties

    {
        // See https://go.microsoft.com/fwlink/?LinkId=733558
        // for the documentation about the tasks.json format
        "version": "2.0.0",
        "presentation": {
            "panel": "new"
        },
        "tasks": [
            {
                "taskName": "TS - Compile current file",
                "type": "shell",
                "command": "tsc ${file}",
                "problemMatcher": [
                    "$tsc"
                ]
            }
        ]
    }
    
    0 讨论(0)
提交回复
热议问题