vscode-code-runner
vscode-code-runner copied to clipboard
Does not work with Golang Modules
- VS Code Version: 1.37.1
- OS Version: 10.14.6
- Code Runner Version: 0.9.14
Describe the bug Fails to recognize imports when using go modules
To Reproduce Steps to reproduce the behavior:
- Initialize a go module within a non
GOPATHorGOROOTdirectorygo mod init myplay - Create two go files.
main.goandgreeter/hello.go
// main.go
package main
import (
"fmt"
"myplay/greeter"
)
func main() {
message := greeter.GreetMe("Charlie")
fmt.Println(message)
}
// greeter/hello.go
package greeter
// GreetMe Demo
func GreetMe(name string) string {
return "Hello, " + name + "!"
}
Actual behavior
myplay/main.go:5:2: cannot find package "myplay/greeter" in any of:
/usr/local/opt/go/libexec/src/myplay/greeter (from $GOROOT)
/Users/self/go/src/myplay/greeter (from $GOPATH)
Expected behavior
Print Hello Charlie
Any plan on support Go modules in this extension?
I am getting this same issue... and I don't know how to do it myself, but this could be easy to fix if the /src/ in path was changed to /pkg/
mine looks like this:
go/test/test.go:5:2: cannot find package "rsc.io/quote" in any of:
/usr/local/go/src/rsc.io/quote (from $GOROOT)
/home/wsl/go/src/rsc.io/quote (from $GOPATH)
I checked the directory manually and /src/ doesn't exist but /pkg/ is there and everything besides that is correct.
Also if it helps any... I am using wsl (ubuntu 22.04 LTS) on windows 11 pro. I will also note that it works fine with std lib modules but not for any external modules.