Go: Extract function refactoring errors, can't find imports in $GOPATH/pkg/mod/ #3040
Description
What version of Go, VS Code & VS Code Go extension are you using?
-
Run
go version
to get version of Go
go version go1.13.7 darwin/amd64 -
Run
code -v
orcode-insiders -v
to get version of VS Code or VS Code Insiders
1.42.0
ae08d5460b5a45169385ff3fd44208f431992451
x64 -
Check your installed extensions to get the version of the VS Code Go extension
0.13.0 -
Run
go env GOOS GOARCH
to get the operating system and processor arhcitecture details
darwin
amd64
Share the Go related settings you have added/edited
"[go]": {
},
"go.formatTool": "goimports",
"go.useLanguageServer": true
Describe the bug
I'm in a go modules project, but the "Extract Function" refactoring errors when I try to execute it, because it can't find an import that's located in $GOPATH/pkg/mod.
I expected the extract function refactoring to work. Instead I get an error toast.
Steps to reproduce the behavior:
- Clone
https://github.com/mhansen/nzwirelessmap-fetch
- Select some go code. I'm using these lines as an example that I'd like to extract to a function:
var selectErr bytes.Buffer
selectCmd := exec.Command("/usr/bin/sqlite3", tmpSqlite.Name())
selectCmd.Stdin = sqlF
selectCmd.Stdout = tmpCsv
selectCmd.Stderr = &selectErr
err = selectCmd.Run()
if err != nil {
return fmt.Errorf("couldn't select: %v, stderr: %v", err, selectErr.String())
}
- Command-Shift-P "Go: Extract To Function"
- Type any function name. I used 'hello'
- See error toast, which says:
Defaulting to file scope /Users/mark/projects/nzwirelessmap-fetch/fetch.go for refactoring (provide an explicit scope to change this) fetch.go:18:2: Error: could not import cloud.google.com/go/storage (cannot find package "cloud.google.com/go/storage" in any of: /usr/local/Cellar/go/1.13.7/libexec/src/cloud.google.com/go/storage (from $GOROOT) /Users/mark/go/src/cloud.google.com/go/storage (from $GOPATH))
Yeah, the package isn't present in either of those. It's present in /Users/mark/go/pkg/mod/cloud.google.com/go/storage@v1.5.0
instead.