Repository: go
Issue: x/tools/go/packages: Package.Module is unset for std and cmd modules
Labels: NeedsFix,Tools

The gopackages command (patched as shown at the end) displays the module of each package:
```
xtools$ gopackages  golang.org/x/telemetry
Go package "golang.org/x/telemetry":
	module golang.org/x/telemetry@v0.0.0-20240209200032-7b892fcb8a78
	package telemetry
	has no exported type info
	file /Users/adonovan/go/pkg/mod/golang.org/x/telemetry@v0.0.0-20240209200032-7b892fcb8a78/doc.go
	file /Users/adonovan/go/pkg/mod/golang.org/x/telemetry@v0.0.0-20240209200032-7b892fcb8a78/mode.go
	file /Users/adonovan/go/pkg/mod/golang.org/x/telemetry@v0.0.0-20240209200032-7b892fcb8a78/types.go
	import "golang.org/x/telemetry/internal/telemetry"

xtools$ gopackages ./gopls
Go command "golang.org/x/tools/gopls":
	module golang.org/x/tools/gopls@
	package main
	has no exported type info
	file /Users/adonovan/w/xtools/gopls/main.go
	import "context"
	import "golang.org/x/tools/gopls/internal/cmd"
	import "golang.org/x/tools/gopls/internal/hooks"
	import "golang.org/x/tools/gopls/internal/telemetry"
	import "golang.org/x/tools/gopls/internal/version"
	import "golang.org/x/tools/internal/tool"
	import "os"
```

But for standard packages and tools, it shows nothing:
```
xtools$ gopackages errors
Go package "errors":
	package errors
	has no exported type info
	file /Users/adonovan/w/goroot/src/errors/errors.go
	file /Users/adonovan/w/goroot/src/errors/join.go
	file /Users/adonovan/w/goroot/src/errors/wrap.go
	import "internal/reflectlite"
	import "unsafe"

xtools$ gopackages cmd/link
Go command "cmd/link":
	package main
	has no exported type info
	file /Users/adonovan/w/goroot/src/cmd/link/doc.go
	file /Users/adonovan/w/goroot/src/cmd/link/main.go
	import "cmd/internal/sys"
	import "cmd/link/internal/amd64"
	import "cmd/link/internal/arm"
	import "cmd/link/internal/arm64"
	import "cmd/link/internal/ld"
	import "cmd/link/internal/loong64"
	import "cmd/link/internal/mips"
	import "cmd/link/internal/mips64"
	import "cmd/link/internal/ppc64"
	import "cmd/link/internal/riscv64"
	import "cmd/link/internal/s390x"
	import "cmd/link/internal/wasm"
	import "cmd/link/internal/x86"
	import "fmt"
	import "internal/buildcfg"
	import "os"
```

This seems like a bug. Even if "go list" doesn't report Module information for standard packages, go/packages should probably synthesize something. Either way, it should document what it actually does.




```
diff --git a/go/packages/gopackages/main.go b/go/packages/gopackages/main.go
index bf0b5043fc..706f13a99a 100644
--- a/go/packages/gopackages/main.go
+++ b/go/packages/gopackages/main.go
@@ -104,6 +104,7 @@ func (app *application) Run(ctx context.Context, args ...string) error {
        default:
                return tool.CommandLineErrorf("invalid mode: %s", app.Mode)
        }
+       cfg.Mode |= packages.NeedModule
 
        lpkgs, err := packages.Load(cfg, args...)
        if err != nil {
@@ -162,6 +163,9 @@ func (app *application) print(lpkg *packages.Package) {
                kind += "package"
        }
        fmt.Printf("Go %s %q:\n", kind, lpkg.ID) // unique ID
+       if mod := lpkg.Module; mod != nil {
+               fmt.Printf("\tmodule %s@%s\n", mod.Path, mod.Version)
+       }
        fmt.Printf("\tpackage %s\n", lpkg.Name)
 
        // characterize type info
```