-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/tools/gopls: extend LinkTarget to support http:// scheme and substitution of {package} and {version} #66389
Comments
@hyangah looking through the gopls issues about this setting, I read #51848 (comment)
Feel free to give a try to https://code.pfad.fr/vanitydoc/ (it is quite new and maybe bit rough). Its original goal is to generate static HTML for hosting at a vanity-URL, however it serves quite well as a local server of documentation. To serve the module in the current folder, run:
|
CC @adonovan, who has recently integrated a simple documentation viewer into gopls, and may find this interesting. The behavior of linktarget seems like a bug. It should be possible to use a local http server. Perhaps we can avoid prepending a scheme if the linktarget already has a scheme. Tentatively putting this in the gopls@v0.16.0 milestone, and marking as help wanted. |
Looking at the codebase, there are 2 conditions I think it would be nice to fix those as well (vanitydoc supports URLs with version info). For instance by adding 2 fields type DocumentationOptions struct {
// HoverKind controls the information that appears in the hover text.
// SingleLine and Structured are intended for use only by authors of editor plugins.
HoverKind HoverKind
// LinkTarget controls where documentation links go.
// It might be one of:
//
// * `"godoc.org"`
// * `"pkg.go.dev"`
//
// If company chooses to use its own `godoc.org`, its address can be used as well.
//
// Modules matching the GOPRIVATE environment variable will not have
// documentation links in hover.
LinkTarget string
// LinkTargetScheme controls the documentation link scheme.
// "https://" by default
LinkTargetScheme string
// LinkTargetWithModuleVersion controls addition of the module version to the documentation URL.
// If set to "true" (by default when LinkTarget is "pkg.go.dev", false otherwise),
// the version will be appended to the module URL,
// e.g. pkg.go.dev/example.com/module@v1.0/package instead of godoc.org/example.com/module/package
LinkTargetWithModuleVersion bool
// LinksInHover toggles the presence of links to documentation in hover.
LinksInHover bool
} |
Hi Oliver, thanks for your interest in improving gopls' documentation rendering. Please build gopls at master and try out the new "Source Action > View package documentation" feature in VS Code (or your editor's equivalent); I think we'll find we're working towards a common purpose. I haven't looked at vanitydoc yet, but perhaps its features can be incorporated directly into gopls, making it easier for users to discover and use. I agree the LinkTarget field should be able to select insecure HTTP. We may need to permit an optional http: or https: prefix on it. (See also https://go.dev/cl/572037/1, in which the special value "gopls" enables use of gopls' new internal web server.) |
This look neat! Especially the "click to open back in vscode"! I got a panic when trying to view the documentation of Do you have any document indicating the state of this viewer and its goal? Or is it only scattered as
The pages under https://code.pfad.fr/vanitydoc/ have been rendered with vanitydoc. The original goal was to generate static websites, and then I realized that I could that locally on the fly from the gomodcache. For vanitydoc it would be greatly beneficial to have an importable package able to produce HTML documentation for chunks of ast (with control regarding the generated links), because escaping HTML and navigating the ast is quite cumbersome: https://codeberg.org/pfad.fr/vanitydoc/src/branch/main/template/ast.go (might not be accessible due to scheduled maintenance) |
And what to you think of the proposition to add the |
Thanks!
Thanks, I can reproduce it. I have filed it as #66449.
No, sorry; the scattered TODOs are the only record.
All of these are indeed missing features, and we would welcome CLs to address any of them.
In earlier discussions about this new feature, I too thought it would have been greatly beneficial to have an importable package able to produce HTML documentation for chunks of ast (it is indeed cumbersome), and was hoping to extract parts of pkgsite to achieve that. But eventually I realized that the representation of the package is so different (and richer) in gopls that it would be counterproductive to try to factor most of the rendering. But I do think we should try to share (or steal) the tricky syntax-to-HTML logic. (The old cmd/godoc contains one or two similar algorithms too.) |
I don't think splitting the URL into such small parts is the way to go. I think it would be simpler to redefine the existing single string so that is interpreted as a URL prefix, onto which a suffix like |
There are 2 distinct issues. Ability to specify the schemeInstead of having an additional parameter, the scheme could be automatically added if missing:
This one can be "easily" managed without adding a parameter Does the documentation support
|
I agree that adding an https:// prefix only if no scheme is already present seems reasonable.
Perhaps a more general approach is needed, supporting template strings such as the following:
For compatibility, existing strings that don't contain (Perhaps the
Just curious: how did you arrange for the local host name |
Sounds good! I would suggest
I stripped a lot of information with my parenthesis 🙈, here is my actual setup:
I documented this today on my blog https://log.pfad.fr/2024/vanitydoc-offloaded/ I would love to make some CLs, however I am currently spending way too much time on unpaid (open-source) work and need some freelance-contract first 😆 |
Actually |
gopls version
0.15.2-1 (on arch linux)
go env
(not relevant, I believe)
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:
I have setup a service file to start this automatically under localhost:
http://localhost:8080
(actually I am usinghttp://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#OpenEditor and settings
settings.json
of vscode:Possible fix
Currently the
s
ofhttps
is hard-codedmsg := 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
The text was updated successfully, but these errors were encountered: