VSCoders, I need your help

Some days ago I was denied JetBrains OSS development license renewal.

Now I am dealing with VSCode configuration in order to achieve the same functionality. e.g. run/debug tests per file etc

I am looking for working examples of launch.json & tasks.json

Link to the github zig project based on vscode would be very helpful

Thank you in advance

I do something weird here! In general, I find dealing with tasks.json cumbersome. So, I have just a single global tasks, that runs ./make.ts file in the root of the repository:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "make.ts",
            "type": "shell",
            "command": "${workspaceFolder}/make.ts",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": false,
                "clear": true
            },
            "group": "build",
            "problemMatcher": {
                "owner": "make.ts",
                "fileLocation": [
                    "autoDetect",
                    "${workspaceFolder}"
                ],
                "pattern": {
                    "regexp": "^(ok\\.)?(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 2,
                    "line": 3,
                    "column": 4,
                    "severity": 5,
                    "message": 6
                }
            }
        }
    ]
}

And then in the root of my repo I have make.ts which looks like this:

#!/usr/bin/env -S deno run --allow-all
// @ts-nocheck
import $ from "jsr:@david/dax";

await $`./zig/zig build vopr -- 18257197606457810748`;

So, if I need to run something specific, I just go and edit make.ts to spawn the commands I need.

I use deno and the dax library as that’s my preferred way to script things, but are more reasonable person would probably stick to just make.sh. Alternatively, replacing deno with bun would also be reasonable: bun is Zig, it starts up a bit faster, and it has $ built-in.

2 Likes

Build (tasks.json):

{
    "tasks": [
        {
            "command": "zig build --summary all",
            "group": "build",
            "label": "build",
            "presentation": {
                "clear": true,
                "echo": true,
                "focus": false,
                "panel": "shared",
                "reveal": "silent",
                "showReuseMessage": false
            },
            "problemMatcher": [
                "$zig"
            ],
            "promptOnClose": false,
            "type": "shell"
        },
        {
            "command": "zig build test --summary all",
            "group": "test",
            "label": "test",
            "presentation": {
                "clear": true,
                "echo": true,
                "focus": false,
                "panel": "shared",
                "reveal": "always",
                "showReuseMessage": false
            },
            "problemMatcher": [
                "$zig"
            ],
            "promptOnClose": false,
            "type": "shell"
        }
    ],
    "version": "2.0.0"
}

Debug launch.json:

{
    "configurations": [
        {
            "args": [],
            "cwd": "${workspaceFolder}",
            "name": "Debug",
            "preLaunchTask": "build",
            "program": "${workspaceFolder}/zig-out/bin/hello",
            "request": "launch",
            "type": "lldb"
        }
    ],
    "version": "0.2.0"
}

The first task (labeled build) is called when starting debugging from preLaunchTask to run zig build. Debugging expects the CodeLLDB extension.
The second task runs the tests (labeled test) using zig build test.
Enable Build On Save to run zig build check and display all errors in the vscode.


More information for debugging using vscode:

2 Likes

i got link to config files from vscode zig ext. contributor

you need to use latest pre-release version 0.6.0

but debug of separated zig files works only if file in question does not have dependencies :joy:

1 Like

Quite old and I haven’t used it recently, but it might help you with config zlibrary-template.

1 Like