Skip to content
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: go doc links to symbols in the current package or non-fully-qualified packages do not render as links in tooltips #61677

Open
nikos-atwise opened this issue Jul 28, 2023 · 2 comments
Assignees
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@nikos-atwise
Copy link

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:

package sample

import "encoding/json"

// This is a sample go doc comment.
//   - [A regular link] works fine.
//   - So does a fully-qualified link to a builtin like [encoding/json.Marshal].
//   - And even non-builtins like [github.com/vmihailenco/msgpack/v5.Marshal].
//
// However...
//   - A link to a symbol accessible through an alias does not: [json.Marshal]
//   - Neither does a link to a symbol in the current package: [Bar]
//
// [A regular link]: http://example.com
type Foo struct{}
type Bar struct{}

func (Foo) F() {
	json.Marshal(nil)
}

This tooltip is shown when I hover over Foo in the editor:

Screenshot 2023-07-28 at 11 15 39 PM
@suzmue suzmue changed the title go doc links to symbols in the current package or non-fully-qualified packages do not render as links in tooltips x/tools/gopls: go doc links to symbols in the current package or non-fully-qualified packages do not render as links in tooltips Jul 31, 2023
@suzmue suzmue transferred this issue from golang/vscode-go Jul 31, 2023
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jul 31, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jul 31, 2023
@suzmue suzmue modified the milestones: Unreleased, gopls/later Jul 31, 2023
@findleyr findleyr self-assigned this Sep 10, 2024
@findleyr findleyr modified the milestones: gopls/backlog, gopls/v0.17.0 Sep 10, 2024
@adonovan
Copy link
Member

adonovan commented Sep 10, 2024

A related bug: clicking on a doc link such as [fmt.Println] only works if the package fmt is imported under its usual name; for a package like "path" that is usually imported under the name pkgpath, the doc link must read [pkgpath.Join], which is not what a user would ever write in a doc comment.

(Fixed by https://go.dev/cl/612045.)

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/612045 mentions this issue: gopls/internal/golang: Definitions: support renaming imports in doc links

gopherbot pushed a commit to golang/tools that referenced this issue Sep 11, 2024
…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 <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Alan Donovan <adonovan@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants