Skip to content

prime31/vscode-zig

 
 

Repository files navigation

Zig Builder

Smashes together the multi-command macros and ripgrep/fzf and then adds on top build commands that parse your zig build --help output letting you select your build target easily.

Features

  • provides a parser for finding zig build targets
  • keyboard shortcut and VS Code commands for building the last target or choosing a target to build
  • easy setup for debugging your last built target with CodeLLDB

Usage

Direct Builds

  • cmd/ctrl+shift+r runs the zig.buildLastTarget command which will prompt you for a target the first time it is run and run it directly thereafter
  • cmd/ctrl+shift+alt+r runs the zig.buildTarget command which will always prompt you for a target
  • you can also can wire those commands up to whatever keybindings you want or use the command palette to run them

Debugging Setup

  • install the CodeLLDB extension
  • add a launch.json file with the contents below
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Last Target",
            "type": "lldb",
            "request": "launch",
            "program": "${workspaceFolder}/zig-cache/bin/${input:zigLastTarget}",
            "args": [],
        }
    ],
    "inputs": [
        {
            "id": "zigLastTarget",
            "type": "command",
            "command": "zig.build.getLastTargetOrPrompt"
        }
    ]
}

Advanced (you can probably stop reading now)

Using tasks.json

Open your tasks.json file and create two new build tasks (the second is optional). Pay close attention to the input: substitution in the build command and the relevant providers in the inputs section.

{
    "tasks": [
        {
            "label": "Build and Run Specific Target",
            "type": "shell",
            "command": "zig build ${input:zigTarget}",
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "clear": true
            }
        },
        {
            "label": "Build and Run Last Target",
            "type": "shell",
            "command": "zig build ${input:zigLastTarget}",
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "presentation": {
                "clear": true
            }
        }
    ],
    "inputs": [
        {
            "id": "zigTarget",
            "type": "command",
            "command": "zig.build.getTargets",
        },
        {
            "id": "zigLastTarget",
            "type": "command",
            "command": "zig.build.getLastTargetOrPrompt"
        }
    ]
}

The key is to use the commands exposed by the extension as input for your own tasks.

  • zig.build.getTargets: parses your build targets and provides a selection list to choose the one to execute zig build TARGET
  • zig.build.getLastTargetOrPrompt: if a previous target was used this skips parsing the build targets and just runs it, else it is that same as zig.build.getTargets

Note that zig must be in your PATH!

Multi-Command Macros

These settings allow you to create command sequence as one command and bind a key to run them or use the command palette (via the "Multi command: Execute multi command" entry). Commands are defined in your settings.json file in the zig.multiCommand.commands array.

See the documentation for details on use.

Building the Extension

  • install npm and the ludicrious amount of cruft it requires
  • install Visual Studio Code Extensions npm install -g @vscode/vsce
  • install TypeScript and the ludicrous amount of cruft it requires (npm install typescript -g)
  • install ESBuild npm i --save-dev esbuild
  • run npm install to download a pile of dependency cruft
  • run npm run compile
  • run vsce package to generate the vsix file

About

Zig language support for VSCode

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 98.6%
  • Shell 1.4%