Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: generate ./... is defeated by submodules #58723

adonovan opened this issue Feb 24, 2023 · 2 comments

cmd/go: generate ./... is defeated by submodules #58723

adonovan opened this issue Feb 24, 2023 · 2 comments


Copy link

adonovan commented Feb 24, 2023

The session below shows a repo containing a root module and a submodule, and a file that uses both. The command go generate ./... within the submodule directory causes generators to run, but the command go generate ./sub/... from the root directory does nothing---this despite go list ./sub/... reporting the packages of the submodule.

ex$ cat 
use ./sub
use .

ex$ cat go.mod

go 1.19

ex$ ls sub
go.mod	sub.go

ex$ cat sub/go.mod

go 1.19

ex$ cat sub/sub.go
//go:generate echo hello

package sub

ex$ (cd sub && go generate ./...)

ex$ go generate ./sub/...

I think this is a bug and that go generate ./sub/... should cause generators to run on all files of all directories of the packages that would be enumerated by go list ./sub/....

Copy link

Change mentions this issue: gopls: use go generate consistently

Copy link

bcmills commented Feb 24, 2023

Duplicate of #56098

@bcmills bcmills marked this as a duplicate of #56098 Feb 24, 2023
@bcmills bcmills closed this as not planned Won't fix, can't repro, duplicate, stale Feb 24, 2023
gopherbot pushed a commit to golang/tools that referenced this issue Mar 1, 2023
This change establishes that "go generate ./..." from within the gopls
directory will update all generated code in the module to its
canonical version. (Beware that this command doesn't work in the
parent directory due to golang/go#58723.)


- The main 'generate' command now includes the canonical git ref
  name of the LSP protocol used by gopls, and by default it
  clones the repo at this version instead of using the version in
  pjw's home directory. ;-)
  It should deliver identical results for all users without setup.
  The "generated" comment includes an accurate URL.
  The timestamp is removed since it is nondeterministic.
- In addition to the commit hash, the output now reports the git
  ref (branch/tag) name, which is not the same as the
  metadata.version (LSP protocol version) string.
- The go:generate comments are now more prominent in their
  respective files. We hide several that appear in testdata from
  the go command by splitting string literals.
- Improved command documentation for generators.
- Use a slice not map for genTypes so that protocol generation
  is deterministic. (Previously the "created for" comments
  would alternate between TextDocumentFilter_Item{0,1}.)

The generated output has changed trivially ("//x" -> "// x")
because the most recent committed generated files was stale
wrt recent generator changes. Also, line number comments now
start at 1, not zero (eliminating a TODO).

Change-Id: I40e9454d0042507bd64e0d8fab3ce6b1fbe87ddc
Run-TryBot: Alan Donovan <>
gopls-CI: kokoro <>
TryBot-Result: Gopher Robot <>
Reviewed-by: Robert Findley <>
Reviewed-by: Peter Weinberger <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

3 participants