-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: hover: doc link markup ignores import mapping of current file, omits links #61677
Comments
A related bug: clicking on a doc link such as (Fixed by https://go.dev/cl/612045.) |
Change https://go.dev/cl/612045 mentions this issue: |
…inks This CL adds support for jumping to the definition of a doc link when the import is renamed. Before, the doc link had to use the local (renamed) name, which is unnatural; now, it can use either the local name or the package's declared name. + test Updates golang/go#61677 Change-Id: Ibbe18ab1527800c41900d42781677ad892b55cd4 Reviewed-on: https://go-review.googlesource.com/c/tools/+/612045 Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Commit-Queue: Alan Donovan <[email protected]>
The problem here is that func CommentToMarkdown(text string, options *settings.Options) string {
var p comment.Parser
+ p.LookupPackage = func(name string) (importPath string, ok bool) {
+ if name == "json" {
+ return "encoding/json", true
+ }
+ return "", false
+ }
+ p.LookupSym = func(recv, name string) (ok bool) {
+ return name == "Marshal"
+ } We already have an implementation of the necessary hooks, in PackageDocHTML (pkgdoc.go). However the parsing part needs access to a syntax package ( |
(If you were replying to my now-deleted comment, my bad, I actually meant to reply to a different but related issue: #69379 (comment)) |
In fact my comment explains the work needed to address this issue. No worries though. |
I thought this might be an easy fix, but it's not. Some thoughts:
|
Change https://go.dev/cl/623637 mentions this issue: |
@adonovan you might have meant to leave this issue open with your "Updates #X" line, but since you wrote "attempt to fix #X", it still got caught as a "fixes" commit :) |
Indeed--good catch! |
I have fallen for this silly regular expression a number of times before, you're definitely not alone. |
Is your feature request related to a problem? Please describe.
When hovering over a symbol in the editor, currently some go doc links do not render as links in the tooltip.
If the link is to some URL, then it will appear correctly. If the link is to a fully-qualified symbol eg
[encoding/json.Marshal]
then it will also appear correctly. However links to symbols imported in the current package but not fully-qualified will not appear as links.Describe the solution you'd like
For builtins or standard library symbols that are accessible, they should link to their pkg.go.dev pages.
For symbols imported in the current package that are not rooted in the same module as the symbol being hovered on, they should also link to their pkg.go.dev pages. (Of course, they may not actually exist on pkg.go.dev, but I think this is good enough, and I believe GoLand does the same thing - it's been a while since I've used it however.)
For symbols imported in the current package that are rooted in the same module as the symbol being hovered on, I think the tooltip should change to showing the documentation for that symbol, since the full comment text should be available in the current workspace.
Describe alternatives you've considered
None
Additional context
https://tip.golang.org/doc/comment#doclinks describes the rules for links.
Given the code sample:
This tooltip is shown when I hover over
Foo
in the editor:The text was updated successfully, but these errors were encountered: