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: doesn't work with GOPATH vendoring #36155

Closed
ian-mi opened this issue Dec 16, 2019 · 10 comments
Closed

x/tools/gopls: doesn't work with GOPATH vendoring #36155

ian-mi opened this issue Dec 16, 2019 · 10 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

@ian-mi
Copy link

ian-mi commented Dec 16, 2019

What version of Go are you using (go version)?

$ go version
go version go1.12.9 linux/amd64

Does this issue reproduce with the latest release?

Yes

gopls version
golang.org/x/tools/gopls 0.2.2
    golang.org/x/tools/gopls@v0.2.2 h1:ujGisyytgY1VGcmd66wIJ9+wVAfmodXj6daHM43HRXk=

What operating system and processor architecture are you using (go env)?

See logs.

What did you do?

Performed the following steps:

  1. Opened the file fake.go.
  2. Added the import github.com/google/go-cmp/cmp.
  3. Typed cmp.Diff.
  4. Saved the file.
  5. Retyped cmp.Diff.

These steps seem to reliably reproduce the issue.

What did you expect to see?

Expected to see completion results for the newly imported package before saving the file.

What did you see instead?

I saw no completion results for cmp.Diff before saving the file but did after saving.
gopls.log
lsp-trace.log

@gopherbot gopherbot added this to the Unreleased milestone Dec 16, 2019
@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 Dec 16, 2019
@gopherbot
Copy link

Thank you for filing a gopls issue! Please take a look at the Troubleshooting guide, and make sure that you have provided all of the relevant information here.

@stamblerre stamblerre changed the title x/tools/gopls: New import not loaded until file is saved x/tools/gopls: new import not loaded until file is saved Dec 16, 2019
@stamblerre stamblerre modified the milestones: Unreleased, gopls v1.0 Dec 16, 2019
@heschi
Copy link
Contributor

heschi commented Dec 17, 2019

I can't reproduce this with gopls master either in GOPATH or module mode. Can you give master a try?

@ian-mi
Copy link
Author

ian-mi commented Dec 17, 2019

Yes, I was able to reproduce the issue on master but the logs look much different.
gopls.log
lsp-trace.log

@ian-mi
Copy link
Author

ian-mi commented Dec 17, 2019

This particular project is in GOPATH mode using vendored deps. I haven't tried to reproduce the issue in module mode.

@ian-mi
Copy link
Author

ian-mi commented Dec 17, 2019

I've also seen a similar issue when creating a new file gopls won't work in that buffer until the file is saved to disk.

@heschi
Copy link
Contributor

heschi commented Dec 17, 2019

Your logs weirdly don't mention cmp at all, but I was able to reproduce the problem by checking out knative-gcp and following the same steps.

Pretty sure this has something to do with vendoring. I get errors like

[Error - 3:46:18 PM] 2019/12/17 15:46:18 no dep handle: no metadata for github.com/google/knative-gcp/vendor/github.com/google/go-cmp/cmp
        package = github.com/google/knative-gcp/vendor/github.com/google/go-cmp/cmp

which are quite suspicious.

@heschi
Copy link
Contributor

heschi commented Dec 17, 2019

At a bare minimum, this code simply won't work with GOPATH vendoring.
https://github.com/golang/tools/blob/210e553fe1f64b5f29af9b359e51cb5216e1cd8e/internal/lsp/cache/check.go#L312

@heschi
Copy link
Contributor

heschi commented Dec 17, 2019

There's also some code path where we do go list on an import path, which also doesn't work; afaict you have to list the vendor path, e.g. github.com/google/knative-gcp/vendor/github.com/google/go-cmp/cmp.

@heschi
Copy link
Contributor

heschi commented Dec 17, 2019

That is probably happening in the go/packages overlay support, which needs to augment the response with the packages that are imported only in the overlay.

Sigh.

@stamblerre stamblerre changed the title x/tools/gopls: new import not loaded until file is saved x/tools/gopls: doesn't work with GOPATH vendoring Dec 19, 2019
@heschi heschi modified the milestones: gopls/v1.0.0, gopls/v0.3.0 Jan 15, 2020
@stamblerre stamblerre added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 16, 2020
@gopherbot
Copy link

Change https://golang.org/cl/215904 mentions this issue: internal/lsp/cache: fix GOPATH vendoring

@golang golang locked and limited conversation to collaborators Jan 23, 2021
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

4 participants