diff --git a/internal/protogen/goldentest/goldentest.go b/internal/protogen/goldentest/goldentest.go index 0902ad78..f8abc319 100644 --- a/internal/protogen/goldentest/goldentest.go +++ b/internal/protogen/goldentest/goldentest.go @@ -53,7 +53,7 @@ func Run(t *testing.T, regenerate bool) { // Compile each package, using this binary as protoc-gen-go. for _, sources := range packages { - args := []string{"-Itestdata", "--go_out=paths=source_relative:" + workdir} + args := []string{"-Itestdata", "--go_out=paths=source_relative,annotate_code:" + workdir} args = append(args, sources...) Protoc(t, args) } @@ -63,6 +63,9 @@ func Run(t *testing.T, regenerate bool) { if info.IsDir() { return nil } + if strings.HasSuffix(genPath, ".meta") { + return nil + } // For each generated file, figure out the path to the corresponding // golden file in the testdata directory. diff --git a/protogen/protogen.go b/protogen/protogen.go index cdfccceb..a2de5acd 100644 --- a/protogen/protogen.go +++ b/protogen/protogen.go @@ -1015,12 +1015,19 @@ func (g *GeneratedFile) metaFile(content []byte) (string, error) { switch spec := spec.(type) { case *ast.TypeSpec: annotate(spec.Name.Name, spec.Name) - if st, ok := spec.Type.(*ast.StructType); ok { + switch st := spec.Type.(type) { + case *ast.StructType: for _, field := range st.Fields.List { for _, name := range field.Names { annotate(spec.Name.Name+"."+name.Name, name) } } + case *ast.InterfaceType: + for _, field := range st.Methods.List { + for _, name := range field.Names { + annotate(spec.Name.Name+"."+name.Name, name) + } + } } case *ast.ValueSpec: for _, name := range spec.Names {