When clicking on an imported Go package in VS Code, its GoDoc at pkg.go.dev will be opened by default. This is a feature of the Go Language Server (gopls). It works fine for packages from the standard library, but will display an error on the website if it is a private package. In most cases, when clicking onto an imported package, I want to navigate into that package.
Don’t Open the Docs in the Browser
All gopls settings can be configured in the global settings.json
file in VS Code. The abovementioned behavior is configurable via the
importShortcut
key, which is an enum with three
possible values:
Link
: Open the link in the Go documentation.Definition
: Go to the package definition. This is probably what you want.Both"
: CombinesLink
andDefinition
.
Therefore, in order to only navigate to the package definition, your gopls configuration has to look like this:
{ ... "gopls": { "importShortcut": "Definition" } }
For further navigation settings of gopls, take a look at the official reference.