Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Comments ¶
type Comments struct { // Leading is the comment that exists before // a proto type's definition. // // /* I'm a leading comment. */ // message Foo {} // Leading string // Trailing is the comment that exists // immediately after a proto type's definition. // // message Foo {} /* I'm a trailing comment. */ // Trailing string // LeadingDetached are comments that exists // before a proto type's definition, separated // by at least one newline. // // /* I'm a leading detached comment. */ // // message Foo {} // LeadingDetached []string }
Comments represents a Proto location's comment details.
type Finder ¶
type Finder struct {
// contains filtered or unexported fields
}
Finder is used to map location paths to their corresponding locations. The Finder is meant to be used on a per-file basis; each file can access the Finder to determine the span for their individual field types.
The locations map is keyed based on a unique representation of location paths.
func NewFinder ¶
func NewFinder(src *descriptor.SourceCodeInfo) *Finder
NewFinder constructs a *Finder for a specific file.
type ID ¶
type ID int32
ID is used to identify a variety of Proto types. These identifiers are not clearly documented, unfortunately. However, they can be found in the FileDescriptorSet found in the protoc-gen-go plugin.
The following document should be treated as the source of truth for a variety of different Proto types: https://github.com/golang/protobuf/blob/master/protoc-gen-go/descriptor/descriptor.proto
The syntax, for example, is identified by 12, and its corresponding path is [12]. This is determined by the following line: https://github.com/golang/protobuf/blob/master/protoc-gen-go/descriptor/descriptor.proto#L89
const ( Syntax ID = 12 Package ID = 2 FileOption ID = 8 Message ID = 4 Field ID = 2 NestedType ID = 3 MessageEnum ID = 4 Oneof ID = 8 Enum ID = 5 EnumValue ID = 2 EnumOption ID = 3 Service ID = 6 Method ID = 2 MethodRequest ID = 2 MethodResponse ID = 3 Name ID = 1 EnumValueNumber ID = 2 FieldLabel ID = 4 FieldNumber ID = 3 FieldType ID = 5 FieldTypeName ID = 6 AllowAlias ID = 2 JavaPackage ID = 1 JavaOuterClassname ID = 8 JavaMultipleFiles ID = 10 GoPackage ID = 11 )
The following identifiers represent Proto types, options, and/or qualitities of a specific type. All of the available Proto types are documented in in the language specification. For more, see: https://developers.google.com/protocol-buffers/docs/reference/proto3-spec
type Location ¶
Location is a convenience wrapper for working with Proto source locations. It contains a span and its corresponding comments.
func NewLocation ¶
func NewLocation(l *descriptor.SourceCodeInfo_Location) Location
NewLocation creates a new Location from the Proto source location.
type Path ¶
type Path []int32
Path represents a Proto location path.
func (Path) Scope ¶
Scope adds field-specific scope to this Path. The path is scoped by adding a specific proto identifier, along with its index.
Adding scope to a proto file's first message type, for example, is done by,
p.Scope(Message, 0)
type Span ¶
type Span [2]int32
Span represents a Proto location span. A Span always has exactly three or four elements: start line, start column, end line (optional, otherwise assumed same as start line), end column. These are packed into a single field for efficiency.
We only ever need to display the initial line and column, so we ignore the remaining elements, i.e. the end line and end column.
Note that line and column numbers are zero-based. We purposefully add 1 to each before displaying to a user.