Skip to content

tinygo-org/vscode-tinygo

Repository files navigation

Visual Studio Code support for TinyGo

This is a simple extension to add TinyGo support to Visual Studio Code.

The extension in action

Features

Right now the only feature this extension supports is setting the right environment variables in the .vscode/settings.json of your workspace. For example, it may set the following configuration to work with the BBC micro:bit:

{
    "go.toolsEnvVars": {
        "GOOS": "linux",
        "GOARCH": "arm",
        "GOROOT": "/home/user/.cache/tinygo/goroot-go1.14-f930d5b5f36579e8cbd1c139012b3d702281417fb6bdf67303c4697195b9ef1f-syscall",
        "GOFLAGS": "-tags=cortexm,baremetal,linux,arm,nrf51822,nrf51,nrf,microbit,tinygo,gc.conservative,scheduler.tasks"
    }
}

To use it, click on the TinyGo status bar element at the bottom of the screen and select a target. Alternatively, you could open the command palette and search for TinyGo target.

Notes:

  • It is probably necessary to reload the window once you've set a new TinyGo target. You will be prompted for this if it's necessary.
  • If the Go extension asks you to rebuild tools because the GOROOT changed, don't do that. It will result in errors and not do what you expect. This is something that should be improved in a future version.

Requirements

This extension depends on the following:

Development

Make sure to checkout preview/playground git submodule. You can do this with the following command:

git submodule update --init

For development, you can use the following .vscode/tasks.json file:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "npm",
            "script": "watch",
            "problemMatcher": "$tsc-watch",
            "isBackground": true,
            "presentation": {
                "reveal": "never"
            },
            "group": "build",
            "label": "npm: watch",
            "detail": "tsc -watch -p ./"
        },
        {
            "type": "npm",
            "script": "compile",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [],
            "label": "npm: compile",
            "detail": "tsc -p ./",
            "dependsOn": ["webworker.bundle.js"],
        },
        {
            "type": "shell",
            "command": "make",
            "args": ["preview/playground/worker/webworker.bundle.js"],
            "group": "build",
            "label": "webworker.bundle.js",
        }
    ]
}

and the following .vscode/launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Run Extension",
            "type": "extensionHost",
            "request": "launch",
            "args": [
                "--extensionDevelopmentPath=${workspaceFolder}"
            ],
            "outFiles": [
                "${workspaceFolder}/out/**/*.js"
            ],
            "preLaunchTask": "${defaultBuildTask}"
        }
    ]
}

To create an extension as a package, run the following command:

vsce package

This creates a new vscode-tinygo-<version>.vsix file that you can install directly in VS Code.