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: gopls fails to resolve definition #47825

Closed
matthiasgeihs opened this issue Aug 19, 2021 · 5 comments
Closed

x/tools/gopls: gopls fails to resolve definition #47825

matthiasgeihs opened this issue Aug 19, 2021 · 5 comments
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@matthiasgeihs
Copy link

What version of Go, VS Code & VS Code Go extension are you using?

  • go version
    • 1.16.6
  • gopls -v version
    • 0.7.1
  • code -v
    • 1.59.0
  • version of the VS Code Go extension
    • 0.27.1

Describe the bug

VSCode fails to resolve some type definitions when gopls is enabled.
The following error is printed on the gopls console output:

[Error - 11:19:32 AM] Request textDocument/definition failed.
  Message: no package for given file position
  Code: 0 

Steps to reproduce the behavior:

  1. Download and open project go-perun in VSCode.
  2. Ensure that gopls is enabled.
  3. Open file client/client_role_test.go.
  4. On line 31, right click ctest.RoleSetup.
  5. Select Go to Definition.

Expected behavior: The editor opens the location of the definition.
Actual behavior: The editor shows No definition for 'RoleSetup'.

Note: The type definition is resolved correctly when gopls is disabled.

@hyangah hyangah changed the title Gopls fails to resolve definition x/tools/gopls: gopls fails to resolve definition Aug 19, 2021
@hyangah hyangah transferred this issue from golang/vscode-go Aug 19, 2021
@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 Aug 19, 2021
@gopherbot gopherbot added this to the Unreleased milestone Aug 19, 2021
@hyangah hyangah added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 19, 2021
@hyangah hyangah modified the milestones: Unreleased, gopls/v0.7.2 Aug 19, 2021
@hyangah
Copy link
Contributor

hyangah commented Aug 19, 2021

Thanks @matthiasgeihs for the report with the repro case.
This looks like a bug introduced in gopls@v0.7.1.
A temporary workaround will be to downgrade gopls@v0.7.0 :-(

@heschi
Copy link
Contributor

heschi commented Aug 19, 2021

I added a little debug logging. It looks like a mismatch in parse modes; the check at https://cs.opensource.google/go/x/tools/+/master:internal/lsp/source/util.go;l=300;drc=f8cfadacc87adf3dd49cc1c165eb4f70931fc6fe is failing for both packages returned by PackagesForFile. I suspect https://golang.org/cl/333689 but didn't verify.

@gopherbot
Copy link

Change https://golang.org/cl/347563 mentions this issue: internal/lsp/source: consider test variants when finding pkg from pos

@findleyr
Copy link
Contributor

findleyr commented Sep 3, 2021

@matthiasgeihs thanks very much for the report, especially with the repro.

It looks like a mismatch in parse modes;

This problem was actually that this particular package is imported as an intermediate test variant, which we had started filtering out. As a result, we couldn't find a package for the object position. CL 347563 contains a fix.

@gopherbot
Copy link

Change https://golang.org/cl/348372 mentions this issue: [gopls-release-branch.0.7] internal/lsp/source: consider test variants when finding pkg from pos

gopherbot pushed a commit to golang/tools that referenced this issue Sep 8, 2021
…s when finding pkg from pos

When resolving a position to a package we must consider all packages,
including intermediate test variants. This manifests, for example, when
jumping to definition in a package that is imported as a test variant
(see golang/go#47825).

For now, fix this by threading through an 'includeTestVariants' flag to
PackagesForFile. This isn't pretty, but should be a trivially safe
change: the only effect will be to increase the number of packages
considered in FindPackageFromPos. Since we are discussing future changes
to the API for querying packages from the snapshot, now did not seem
like a good time to undertake significant refactoring.

A regtest based on the original issue is included.

This CL is joint with rstambler@golang.org.

Fixes golang/go#47825

Co-authored-by: Rebecca Stambler <rstambler@golang.org>
Change-Id: I4693ec69b50ed4acd569cff87883769c1edf332b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/347563
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>
(cherry picked from commit e5f719f)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/348372
@golang golang locked and limited conversation to collaborators Sep 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. 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