Skip to content

Commit

Permalink
protoc-gen-go: put all imports in one section (#720)
Browse files Browse the repository at this point in the history
Keep plugin imports and non-plugin imports in the same section, but
don't try to split stdlib and non-stdlib imports into different
sections. Consistent with using astutil to insert all imports from a
blank slate.
  • Loading branch information
neild authored and dsnet committed Sep 28, 2018
1 parent 7b18087 commit 7011d38
Show file tree
Hide file tree
Showing 37 changed files with 40 additions and 87 deletions.
3 changes: 1 addition & 2 deletions conformance/internal/conformance_proto/conformance.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions jsonpb/jsonpb_test_proto/more_test_objects.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions jsonpb/jsonpb_test_proto/test_objects.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions proto/proto3_proto/proto3.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions proto/test_proto/test.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/descriptor/descriptor.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 4 additions & 15 deletions protoc-gen-go/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1303,26 +1303,15 @@ func (g *Generator) generateImports() {
for importPath := range g.addedImports {
imports[importPath] = g.GoPackageName(importPath)
}
g.P("import (")
// Standard library imports.
g.P(g.Pkg["fmt"] + ` "fmt"`)
g.P(g.Pkg["math"] + ` "math"`)
for importPath, packageName := range imports {
if !strings.Contains(string(importPath), ".") {
g.P(packageName, " ", GoImportPath(g.ImportPrefix)+importPath)
}
}
g.P()
// Third-party imports.
//
// We almost always need a proto import. Rather than computing when we
// do, which is tricky when there's a plugin, just import it and
// reference it later. The same argument applies to the fmt and math packages.
g.P("import (")
g.P(g.Pkg["fmt"] + ` "fmt"`)
g.P(g.Pkg["math"] + ` "math"`)
g.P(g.Pkg["proto"]+" ", GoImportPath(g.ImportPrefix)+"github.com/golang/protobuf/proto")
for importPath, packageName := range imports {
if strings.Contains(string(importPath), ".") {
g.P(packageName, " ", GoImportPath(g.ImportPrefix)+importPath)
}
g.P(packageName, " ", GoImportPath(g.ImportPrefix)+importPath)
}
g.P(")")
g.P()
Expand Down
3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/deprecated/deprecated.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/extension_base/extension_base.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/extension_extra/extension_extra.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/extension_user/extension_user.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/grpc/grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/import_public/a.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/import_public/b.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/import_public/sub/a.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/import_public/sub/b.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/imports/fmt/m.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/imports/test_a_1/m1.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/imports/test_a_1/m2.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/imports/test_a_2/m3.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/imports/test_a_2/m4.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/imports/test_b_1/m1.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/imports/test_b_1/m2.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/imports/test_import_a1m1.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/imports/test_import_a1m2.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/imports/test_import_all.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/multi/multi1.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/multi/multi2.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/multi/multi3.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/my_test/test.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions protoc-gen-go/testdata/proto3/proto3.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions ptypes/any/any.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7011d38

Please sign in to comment.