cmd/protoc-gen-go: generate forwarding decls for ExtensionDescs

When publicly importing a package with extension definitions, generate
forwarding declarations for the "E_..." ExtensionDesc var:

    var E_ExtensionField = publicimport.E_ExtensionField

Change-Id: Ifd57c487c3a44f303c2c098a42ea249b219b734f
Reviewed-on: https://go-review.googlesource.com/c/145498
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/cmd/protoc-gen-go/internal_gengo/main.go b/cmd/protoc-gen-go/internal_gengo/main.go
index 89d4011..96b27fb 100644
--- a/cmd/protoc-gen-go/internal_gengo/main.go
+++ b/cmd/protoc-gen-go/internal_gengo/main.go
@@ -194,6 +194,11 @@
 			g.P("const ", value.GoIdent.GoName, " = ", enum.GoIdent.GoName, "(", value.GoIdent, ")")
 		}
 	}
+	for _, ext := range impFile.Extensions {
+		ident := extensionVar(impFile, ext)
+		g.P("var ", ident.GoName, " = ", ident)
+		g.P()
+	}
 	g.P()
 }
 
@@ -823,7 +828,7 @@
 		name = name.Parent()
 	}
 
-	g.P("var ", extensionVar(f, extension), " = &", protogen.GoIdent{
+	g.P("var ", extensionVar(f.File, extension), " = &", protogen.GoIdent{
 		GoImportPath: protoPackage,
 		GoName:       "ExtensionDesc",
 	}, "{")
@@ -848,7 +853,7 @@
 }
 
 // extensionVar returns the var holding the ExtensionDesc for an extension.
-func extensionVar(f *fileInfo, extension *protogen.Extension) protogen.GoIdent {
+func extensionVar(f *protogen.File, extension *protogen.Extension) protogen.GoIdent {
 	name := "E_"
 	if extension.ParentMessage != nil {
 		name += extension.ParentMessage.GoIdent.GoName + "_"
@@ -922,7 +927,7 @@
 	g.P(protogen.GoIdent{
 		GoImportPath: protoPackage,
 		GoName:       "RegisterExtension",
-	}, "(", extensionVar(f, extension), ")")
+	}, "(", extensionVar(f.File, extension), ")")
 	if isExtensionMessageSetElement(gen, extension) {
 		goType, pointer := fieldGoType(g, extension)
 		if pointer {