• Home
  • Raw
  • Download

Lines Matching +full:plugin +full:- +full:syntax +full:- +full:import +full:- +full:meta

2 // Use of this source code is governed by a BSD-style
13 import (
43 const goPackageDocURL = "https://protobuf.dev/reference/go/go-generated#package"
45 // Run executes a function as a protoc plugin.
47 // It reads a CodeGeneratorRequest message from os.Stdin, invokes the plugin
52 func (opts Options) Run(f func(*Plugin) error) {
59 func run(opts Options, f func(*Plugin) error) error {
76 // Errors from the plugin function are reported by setting the
95 // A Plugin is a protoc plugin invocation.
96 type Plugin struct { struct
100 // Files is the set of files to generate and everything they import.
107 // this generator plugin. See the documentation for
123 // If ParamFunc is non-nil, it will be called with each unknown
127 // passed in the --<lang>_out protoc, separated from the output
130 // --go_out=<param1>=<value1>,<param2>=<value2>:<output_directory>
132 // Parameters passed in this fashion as a comma-separated list of
143 // protogen.Run(opts, func(p *protogen.Plugin) error {
148 // ImportRewriteFunc is called with the import path of each package
149 // imported by a generated file. It returns the import path to use
154 // New returns a new Plugin.
155 func (opts Options) New(req *pluginpb.CodeGeneratorRequest) (*Plugin, error) {
156 gen := &Plugin{
165 packageNames := make(map[string]GoPackageName) // filename -> package name
166 importPaths := make(map[string]GoImportPath) // filename -> import path
180 case "import":
185 return nil, fmt.Errorf(`unknown path type %q: want "import" or "source_relative"`, value)
216 // filenames are based on the import path.
221 // Figure out the import path and package name for each file.
228 // .proto source file specifying the full import path of the Go package
234 // import paths may specify M<filename>=<import_path> flags.
236 // The "M" command-line flags take precedence over
248 // The import path must be specified one way or another.
250 "unable to determine Go import path for %q\n\n"+
258 // Check that import paths contain at least a dot or slash to avoid
259 // a common mistake where import path is confused with package name.
261 "invalid Go import path %q for %q\n\n"+
262 "The import path must contain at least one period ('.') or forward slash ('/') character.\n\n"+
267 // then derive a reasonable package name from the import path.
269 // NOTE: The package name is derived first from the import path in
273 // import paths all packages, where it is generally expected that
283 // Consistency check: Every file with the same Go import path should have
303 // The extracted types from the full import set
328 // Create fully-linked descriptors if new extensions were found
346 func (gen *Plugin) Error(err error) { argument
353 func (gen *Plugin) Response() *pluginpb.CodeGeneratorResponse { argument
384 meta, err := g.metaFile(content)
391 Name: proto.String(filename + ".meta"),
392 Content: proto.String(meta),
409 GoImportPath GoImportPath // import path of this file's Go package
411 Enums []*Enum // top-level enum declarations
412 Messages []*Message // top-level message declarations
413 Extensions []*Extension // top-level extension declarations
414 Services []*Service // top-level service declarations
428 func newFile(gen *Plugin, p *descriptorpb.FileDescriptorProto, packageName GoPackageName, importPat… argument
447 prefix = prefix[:len(prefix)-len(ext)]
451 // If paths=import, the output filename is derived from the Go import path.
496 // from the Go import path when separated by a ';' delimiter.
516 func newEnum(gen *Plugin, f *File, parent *Message, desc protoreflect.EnumDescriptor) *Enum { argument
548 func newEnumValue(gen *Plugin, f *File, message *Message, enum *Enum, desc protoreflect.EnumValueDe… argument
549 // A top-level enum value's name is: EnumName_ValueName
552 // For historical reasons, enum value names are not camel-cased.
585 func newMessage(gen *Plugin, f *File, parent *Message, desc protoreflect.MessageDescriptor) *Messag… argument
626 // We assume well-known method names that may be attached to a generated
638 // adding new per-field methods such as setters.
697 func (message *Message) resolveDependencies(gen *Plugin) error {
721 // For code generated by protoc-gen-go, this means a field named
725 // GoIdent is the base name of a top-level declaration for this field.
726 // For code generated by protoc-gen-go, this means a wrapper type named
731 Parent *Message // message in which this field is declared; nil if top-level extension
742 func newField(gen *Plugin, f *File, message *Message, desc protoreflect.FieldDescriptor) *Field { argument
771 func (field *Field) resolveDependencies(gen *Plugin) error {
805 // For code generated by protoc-gen-go, this means a field named
809 // GoIdent is the base name of a top-level declaration for this oneof.
820 func newOneof(gen *Plugin, f *File, message *Message, desc protoreflect.OneofDescriptor) *Oneof { argument
852 func newService(gen *Plugin, f *File, desc protoreflect.ServiceDescriptor) *Service { argument
881 func newMethod(gen *Plugin, f *File, service *Service, desc protoreflect.MethodDescriptor) *Method { argument
893 func (method *Method) resolveDependencies(gen *Plugin) error {
915 gen *Plugin
927 // and import path.
928 func (gen *Plugin) NewGeneratedFile(filename string, goImportPath GoImportPath) *GeneratedFile { argument
966 // the returned name will be qualified (package.name) and an import statement
984 // Import ensures a package is imported by the generated file.
987 // Explicitly importing a package with Import is generally only necessary
988 // when the import will be blank (import _ "package").
989 func (g *GeneratedFile) Import(importPath GoImportPath) { func
998 // Skip removes the generated file from the plugin output.
1003 // Unskip reverts a previous call to Skip, re-including the generated file in
1004 // the plugin output.
1013 // struct field. The "T.sel" syntax is used to identify the method or field
1064 // Modify the AST to include a new import block.
1078 // Construct the import block.
1080 Tok: token.IMPORT,
1185 // A GoIdent is a Go identifier, consisting of a name and import path.
1186 // The name is a single identifier and may not be a dot-qualified selector.
1203 // A GoImportPath is the import path of a Go package.