gopls version
golang.org/x/tools/gopls v0.17.1
go env
n/a
What did you do?
Note: this is a feature request
Given
// This is a dog.
type Dog struct {
Name string `json:"name"`
Age int `json:"age"`
}
type Hound = Dog
// A Puppy is a Dog with an age less than 2.
type Puppy = Dog
I hovered over Hound
and Puppy
What did you see happen?
The hover message reads
type Hound = Dog
and respectively
type Puppy = Dog
A puppy is a dog with an age less than 2.
What did you expect to see?
type Hound = Dog
This is a dog.
type Dog struct {
Name string `json:"name"`
Age int `json:"age"`
}
and respectively
type Puppy = Dog
A puppy is a dog with an age less than 2.
type Dog struct {
Name string `json:"name"`
Age int `json:"age"`
}
I like the semantic that docstrings are inherited if, and only if, the alias provides no docstring of its own.
Editor and settings
n/a
Logs
n/a
Comment From: findleyr
This sounds like a nice improvement. Thanks.
Comment From: adonovan
@jacobzim-stl, did you want to take a crack at implementing the necessary fix? (I heard a rumor from one of my coworkers.)
Comment From: jacobzim-stl
@adonovan I'd love to, unfortunately my bandwidth is a bit limited in the coming weeks. I'll give it an initial shot this weekend. If the implementation gets heavy I might not be able to implement it for a while.
Comment From: gopherbot
Change https://go.dev/cl/644495 mentions this issue: gopls/internal/hover: show underlying type on hover over alias
Comment From: xieyuschen
Hi @jacobzim-stl , I have put the real type definition after the original typeDecl, as the screenshot shows below. I hope it meets your expectations :)
Comment From: jacobzim-stl
Amazing! Thanks @xieyuschen!
Comment From: adonovan
I think this behavior change may have been a mistake; see https://github.com/golang/go/issues/74361#issuecomment-3001485832.