Run godoc Automatically
Tony Metzidis

Tony Metzidis @tonymet

About: Developer and Engineering Manager. Mostly backend & cloud platforms. Currently node.js & golang. Also AWS CSA Associate

Location:
SF Bay Area
Joined:
Feb 9, 2019

Run godoc Automatically

Publish Date: Nov 26 '24
1 0

VSCode has a fantastic task runner, with lots of configuration options for when and how the task should be run.

Let's set up godoc to run whenever you open the project. It will display a push notification linking you to godoc server within your browser.

STEPS to Add

(1) Install godoc via your terminal

 go install golang.org/x/tools/cmd/godoc@latest
Enter fullscreen mode Exit fullscreen mode

(2) Add the task with CTRL-SHIFT-P, "Configure Tasks" . This edits ./vscode/tasks.json
(3) Add the following task to the tasks array (copy the individual task object below)

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "godoc",
            "type": "shell",
            "command": "godoc",
            "options": {
                "cwd": "${workspaceFolder}",
                "shell": {
                    "args": ["-c"],
                    "executable": "/bin/sh"
                }
            },
            "runOptions": {"runOn": "folderOpen"},
            "presentation": {
                "echo": true,
                "reveal": "never",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": false
            },
            "problemMatcher": []
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

(4) Run the task. You can run the task with CTRL-SHIFT-P → "Run Task" → "godoc" or by reopening your window. A notice will show linking you to godoc. Or you can find the link using the "Ports" tab and clicking the godoc URL.

Comments 0 total

    Add comment