location

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2019 License: MIT Imports: 4 Imported by: 0

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.

func (*Finder) Find

func (f *Finder) Find(p Path) (Location, bool)

Find returns the Location for the corresponding Path based on its unique key. If not found, false is returned.

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

type Location struct {
	Span     Span
	Comments Comments
}

Location is a convenience wrapper for working with Proto source locations. It contains a span and its corresponding comments.

func NewLocation

NewLocation creates a new Location from the Proto source location.

type Path

type Path []int32

Path represents a Proto location path.

func (Path) Scope

func (p Path) Scope(typ ID, idx int) Path

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)

func (Path) Target

func (p Path) Target(target ID) Path

Target adds the given target to this Path. The path receives a target to a specific proto type's component by explicitly specifying the target identifier.

Targetting a proto file's package definition, for example, is done by,

p.Target(Package)

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.

func NewSpan

func NewSpan(s []int32) Span

NewSpan constructs a Span from the given slice.

func (Span) Col

func (s Span) Col() int32

Col returns the start column for this Span.

func (Span) Line

func (s Span) Line() int32

Line returns the start line for this Span.

func (Span) String

func (s Span) String() string

String displays this Span as a string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL