Skip to content

x/tools/gopls: extend LinkTarget to support http:// scheme and substitution of {package} and {version} #66389

@oliverpool

Description

@oliverpool

gopls version

0.15.2-1 (on arch linux)

go env

(not relevant, I believe)

GO111MODULE=''
GOARCH='amd64'
GOPRIVATE=''
GOVERSION='go1.22.1'

What did you do?

I have been developing vanitydoc to be able to generate simple HTML documentation at the import path of my go libraries.

This library is also able to generate those files "on-the-fly", for instance running the following command serves the documentation of the standard library, as well as the documentation of the packages in my gomodcache locally:

vanitydoc -gomodcache=$(go env GOMODCACHE) /usr/lib/go/src

I have setup a service file to start this automatically under localhost: http://localhost:8080 (actually I am using http://pkg/) and I ajusted the gopls settings inside vscode to: "ui.documentation.linkTarget": "http://pkg"

What did you see happen?

When clicking on a doc link, the https:// gets prepended: https://http://pkg/src.agwa.name/go-listener@v0.5.1#Open

What did you expect to see?

I would expect to be able to visit the http version: http://pkg/src.agwa.name/go-listener@v0.5.1#Open

Editor and settings

settings.json of vscode:

"gopls": {
    "ui.documentation.linkTarget": "http://pkg"
  }

Possible fix

Currently the s of https is hard-coded msg := fmt.Sprintf("https://%s/%s", options.LinkTarget, link.ImportPath)
https://github.com/golang/tools/blob/c21ae4cabc44594caf9cbfa867a678ad4a2df387/gopls/internal/golang/comment.go#L29

I would propose to move the logic to settings.go:
https://github.com/golang/tools/blob/2d517d51b81102672a95b40c9fea60a65ba3620a/gopls/internal/settings/settings.go#L985

  • if the variable is empty, don't do anything
  • If no scheme is set, set it to https
  • if a scheme is set, use it as-is

Metadata

Metadata

Assignees

No one assigned

    Labels

    ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.help wanted

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions