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: sometimes documentation on hover is not shown #46158
Comments
Thanks for the report. Which gopls commit did you build at? I thought this might be related to recent work on AST trimming, but can't reproduce at tip. Are you able to repro? If so, can you please capture RPC logs, as described here? |
It was built with Unfortunately I can't reproduce it now, it had been in that state for a while, but after restart of VS Code, I can see documentation for this particular function. I'll watch over it and let you know if this repeats. |
I faced a similar issue. But in my case fields of a struct have disappeared. The first commit with this issue is golang/tools@cd1d088. Note that this behavior is inconsistent (see screenshots) Steps to reproduce package main
import (
"github.com/go-pg/pg/v10/orm"
)
func main() {
orm.NewQuery(nil, nil)
(&orm.Query{}).New()
}
And
gopls@09ab05b (master)
gopls@v0.6.11
|
FWIW, I think these are separate issues. @ShoshinNikita you issue seems to clearly be a result of AST trimming. I am not so sure about the original issue. Keeping this as a single issue until I understand it better. |
Change https://golang.org/cl/320550 mentions this issue: |
With the new ParseExported logic, we can lose some unexported fields on exported structs. This can lead to misleading or malformatted hover information. Fix this by ensuring we always extract the Spec from a full parse. Since this path is only hit via user-initiated requests (and should only be hit ~once per request), it is preferable to do the parse on-demand rather than parse via the cache and risk pinning the full AST for the remaining duration of the session. For golang/go#46158 Change-Id: Ib3eb61c3f75e16199eb492e3e129ba875bd8553e Reviewed-on: https://go-review.googlesource.com/c/tools/+/320550 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
The CL above should fix the issue reported by @ShoshinNikita, but I'm still not sure what's going on in the original issue: none of the AST trimming should have dropped comments. So I think we should leave this issue open for a little while in case the problem reoccurs and we can capture logs. Unassigning in the meantime. |
@inliquid: Have you encountered this again, after the CL above? If not, let's close this issue as I think it has been resolved. |
@stamblerre no, haven't seen this so far. |
@findleyr At first, I decided the issue I reported is not completely fixed. But then I understood it is the intended result of AST trimming. Is that correct? Exported function Unexported function |
Thanks for catching that. This must be an edge case that doesn't trigger re-parsing, for some reason. I'll look into it. |
The issue is that in the case of filterFile, we're not finding the hovered declaration at all. The patch of CL 320550 was really too shallow: we need a mechanism for specifying exactly what information is needed to fulfill the hover request, and this mechanism should go through the gopls cache. I'm experimenting with this now, but it will likely turn out not to be a small change. |
Change https://golang.org/cl/333689 mentions this issue: |
Change https://golang.org/cl/333690 mentions this issue: |
When we open a file in a package, independent of whether it is in the workspace, we type check in ParseFull mode. However, several other code paths don't find this better parse mode. We need a better abstraction, but for now improve a couple code paths specifically for the purpose of fixing Hover content. Updates golang/go#46158 Updates golang/go#46902 Change-Id: I34c0432fdba406d569ea963ab4366336068767a2 Reviewed-on: https://go-review.googlesource.com/c/tools/+/333689 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
When enriching identifier info with full syntax, it's cleaner to find the enclosing decl. Use the full decl in hover if we were unable to find a node in the original type-checked package. Update the regtest to exercise hovering in a non-workspace package. Updates golang/go#46158 Change-Id: Ic1772a38fb1758fb57a09da9483a8853cc5498f1 Reviewed-on: https://go-review.googlesource.com/c/tools/+/333690 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
@findleyr I think I found a regression introduced in the last CL (https://golang.org/cl/333690):
Note: it's happening only with packages from std lib and other modules Updated codefunc TestHoverUnexported(t *testing.T) {
const proxy = `
-- golang.org/x/structs@v1.0.0/go.mod --
module golang.org/x/structs
go 1.12
-- golang.org/x/structs@v1.0.0/types.go --
package structs
type Mixed struct {
// Exported comment
Exported int
unexported string
}
func printMixed(m Mixed) {
println(m)
}
`
const mod = `
-- go.mod --
module mod.com
go 1.12
require golang.org/x/structs v1.0.0
-- go.sum --
golang.org/x/structs v1.0.0 h1:Ito/a7hBYZaNKShFrZKjfBA/SIPvmBrcPCBWPx5QeKk=
golang.org/x/structs v1.0.0/go.mod h1:47gkSIdo5AaQaWJS0upVORsxfEr1LL1MWv9dmYF3iq4=
-- main.go --
package main
import "golang.org/x/structs"
func main() {
var m structs.Mixed
_ = m.Exported
}
`
// TODO: use a nested workspace folder here.
WithOptions(
ProxyFiles(proxy),
).Run(t, mod, func(t *testing.T, env *Env) {
env.OpenFile("main.go")
mixedPos := env.RegexpSearch("main.go", "Mixed")
got, _ := env.Hover("main.go", mixedPos)
if !strings.Contains(got.Value, "unexported") {
t.Errorf("Workspace hover: missing expected field 'unexported'. Got:\n%q", got.Value)
}
cacheFile, _ := env.GoToDefinition("main.go", mixedPos)
argPos := env.RegexpSearch(cacheFile, "printMixed.*(Mixed)")
got, _ = env.Hover(cacheFile, argPos)
if !strings.Contains(got.Value, "unexported") {
t.Errorf("Non-workspace hover: missing expected field 'unexported'. Got:\n%q", got.Value)
}
exportedFieldPos := env.RegexpSearch("main.go", "Exported")
got, _ = env.Hover("main.go", exportedFieldPos)
if !strings.Contains(got.Value, "comment") {
t.Errorf("Workspace hover: missing comment for field 'Exported'. Got:\n%q", got.Value)
}
})
} The regression is caused by this code: // Always use the full declaration here if we have it, because the
// dependent code doesn't rely on pointer identity. This is fragile.
if d, _ := fullDecl.(*ast.GenDecl); d != nil {
node = d
} We can't find a comment (see function
|
@ShoshinNikita thank you for that investigation! Moving this to v0.8.0. |
Change https://go.dev/cl/384697 mentions this issue: |
For example in case of
(*url.URL).Query()
:The text was updated successfully, but these errors were encountered: