microsoft / vscode-go

An extension for VS Code which provides support for the Go language. We have moved to https://github.com/golang/vscode-go
Other
5.93k stars 645 forks source link

Adding a module using `go get` from outside vscode is not recognized until go.mod is reopened #3234

Closed daaku closed 4 years ago

daaku commented 4 years ago

Steps

  1. Open a Go project with module mode enabled
  2. go get a new module dependency in a shell, confirm it was added to go.mod.
  3. Use the dependency in an already open .go file in vscode, save it.
  4. See a warning appear about said dependency missing in go.mod.
  5. Open go.mod, see the warning disappear without making any changes.

Setup

Extension Version: 0.14.1 Go Version: go1.14.2 linux/amd64 VSCode Version: 1.45.0 / d69a79b73808559a91206d73d7717ff5f798f23c

hyangah commented 4 years ago

@daaku Are you using the language server? Can you share your extension-related settings (go or [go] prefixes)?

If you enabled the language server, can you please capture the gopls logs following the instruction. I hope that shows us whether the gopls, the go language server, detected the go.mod file change or not.

daaku commented 4 years ago

The go related settings I have are:

    "go.formatTool": "goimports",
    "go.useLanguageServer": true,

I confirmed that this still happens (gopls just got updated to 0.4.1 and the extension to 0.14.2). I captured the log but it contains too much information for me to just share as is. I'll create a empty project and capture the logs and update later.

stamblerre commented 4 years ago

Thanks! It's also fine to redact information in the log if that's easier.

daaku commented 4 years ago

The trace of a new empty project where I open a file with 3 lines of code and reproduce the issue is nearly 1500 lines and 1.5MB in size. That's too much for me to go an audit to make me feel safe sharing.

Here's a set of repro steps, hopefully that's enough:

mkdir gt
cd gt
go mod init github.com/daaku/gt
touch main.go
code .
# wait for vscode to open, open main.go, don't write anything yet
# then back in the terminal
go get github.com/pkg/errors

No go to the vscode window that is open, open main.go and type this in:

package main

import "github.com/pkg/errors"

var foo = errors.WithStack(nil)
  1. Hit save.
  2. See the package gets a yellow squiggly with the warning "github.com/pkg/errors is not in your go.mod file.go".
  3. Click on the go.mod file in the browser sidebar.
  4. The file opens and the warning disappears.
stamblerre commented 4 years ago

Thank you for the repro case - I was able to reproduce the issue. Let's continue the conversation in the upstream gopls issue: https://github.com/golang/go/issues/39124.