Skip to content

Integration with Visual Studio Code

James Tai edited this page Jul 2, 2021 · 2 revisions

Add the following to .vscode/tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "Build current file",
            "command": "coman",
            "args": [
                "build",
                "-o",
                "${workspaceFolder}/build/vscode/release/${relativeFile}",
                "${file}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": ["$gcc"],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "type": "shell",
            "label": "Build current file (debug)",
            "command": "coman",
            "args": [
                "build",
                "-d",
                "-o",
                "${workspaceFolder}/build/vscode/debug/${relativeFile}",
                "${file}"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": ["$gcc"],
            "group": "build"
        },
        {
            "type": "shell",
            "label": "Test current file",
            "command": "coman",
            "args": ["test", "${file}"],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": ["$gcc"],
            "group": {
                "kind": "test",
                "isDefault": true
            }
        }
    ]
}

Add the following to .vscode/launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Run current file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/vscode/debug/${relativeFile}",
            "cwd": "${workspaceFolder}",
            "preLaunchTask": "Build current file (debug)"
        }
    ]
}

Now, you can debug the current file by pressing F5 (tested with C++).

You can press Ctrl+P and type task test to run the tests for the current file.

Clone this wiki locally