const ( // PackageInfoKey is the name of a private attribute set on generated // proto_library rules. This attribute contains a Package record which // describes the library and its sources. PackageKey = "_package" )
func NewLanguage() language.Language
func RuleName(names ...string) string
RuleName returns a name for a proto_library derived from the given strings. For each string, RuleName will look for a non-empty suffix of identifier characters and then append "_proto" to that.
FileInfo contains metadata extracted from a .proto file.
type FileInfo struct { Path, Name string PackageName string Options []Option Imports []string HasServices bool }
Mode determines how proto rules are generated.
type Mode int
const ( // DefaultMode generates proto_library rules. Other languages should generate // library rules based on these (e.g., go_proto_library) and should ignore // checked-in generated files (e.g., .pb.go files) when there is a .proto // file with a similar name. DefaultMode Mode = iota // DisableMode ignores .proto files and generates empty proto_library rules. // Checked-in generated files (e.g., .pb.go files) should be treated as // normal sources. DisableMode // DisableGlobalMode is similar to DisableMode, but it also prevents // the use of special cases in dependency resolution for well known types // and Google APIs. DisableGlobalMode // LegacyMode generates filegroups for .proto files if .pb.go files are // present in the same directory. LegacyMode // PackageMode generates a proto_library for each set of .proto files with // the same package name in each directory. PackageMode // FileMode generates a proto_library for each .proto file. FileMode )
func ModeFromString(s string) (Mode, error)
func (m Mode) ShouldGenerateRules() bool
func (m Mode) ShouldIncludePregeneratedFiles() bool
func (m Mode) ShouldUseKnownImports() bool
func (m Mode) String() string
Option represents a top-level option statement in a .proto file. Only string options are supported for now.
type Option struct { Key, Value string }
Package contains metadata for a set of .proto files that have the same package name. This translates to a proto_library rule.
type Package struct { Name string RuleName string // if not set, defaults to Name Files map[string]FileInfo Imports map[string]bool Options map[string]string HasServices bool }
ProtoConfig contains configuration values related to protos.
This type is public because other languages need to generate rules based on protos, so this configuration may be relevant to them.
type ProtoConfig struct { // Mode determines how rules are generated for protos. Mode Mode // ModeExplicit indicates whether the proto mode was set explicitly. ModeExplicit bool // GoPrefix is the current Go prefix (the Go extension may set this in the // root directory only). Used to generate proto rule names in the root // directory when there are no proto files or the proto package name // can't be determined. // TODO(jayconrod): deprecate and remove Go-specific behavior. GoPrefix string // StripImportPrefix The prefix to strip from the paths of the .proto files. // If set, Gazelle will apply this value to the strip_import_prefix attribute // within the proto_library_rule. StripImportPrefix string // ImportPrefix The prefix to add to the paths of the .proto files. // If set, Gazelle will apply this value to the import_prefix attribute // within the proto_library_rule. ImportPrefix string // contains filtered or unexported fields }
func GetProtoConfig(c *config.Config) *ProtoConfig
GetProtoConfig returns the proto language configuration. If the proto extension was not run, it will return nil.