vscode-code-runner icon indicating copy to clipboard operation
vscode-code-runner copied to clipboard

Does not work with Golang Modules

Open casoetan opened this issue 6 years ago • 2 comments
trafficstars

  • 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:

  1. Initialize a go module within a non GOPATH or GOROOT directory go mod init myplay
  2. Create two go files.
    • main.go and
    • greeter/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

casoetan avatar Aug 24 '19 22:08 casoetan

Any plan on support Go modules in this extension?

linuxus avatar May 10 '20 16:05 linuxus

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.

systematical avatar Mar 12 '24 22:03 systematical