Run godoc Automatically

tonymet

Tony Metzidis

Posted on November 26, 2024

Run godoc Automatically

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.

💖 💪 🙅 🚩
tonymet
Tony Metzidis

Posted on November 26, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related