1package pgs
2
3import (
4	"github.com/golang/protobuf/protoc-gen-go/descriptor"
5)
6
7const (
8	packagePath               int32 = 2  // FileDescriptorProto.Package
9	messageTypePath           int32 = 4  // FileDescriptorProto.MessageType
10	enumTypePath              int32 = 5  // FileDescriptorProto.EnumType
11	servicePath               int32 = 6  // FileDescriptorProto.Service
12	syntaxPath                int32 = 12 // FileDescriptorProto.Syntax
13	messageTypeFieldPath      int32 = 2  // DescriptorProto.Field
14	messageTypeNestedTypePath int32 = 3  // DescriptorProto.NestedType
15	messageTypeEnumTypePath   int32 = 4  // DescriptorProto.EnumType
16	messageTypeOneofDeclPath  int32 = 8  // DescriptorProto.OneofDecl
17	enumTypeValuePath         int32 = 2  // EnumDescriptorProto.Value
18	serviceTypeMethodPath     int32 = 2  // ServiceDescriptorProto.Method
19)
20
21// SourceCodeInfo represents data about an entity from the source. Currently
22// this only contains information about comments protoc associates with
23// entities.
24//
25// All comments have their // or /* */ stripped by protoc. See the
26// SourceCodeInfo documentation for more details about how comments are
27// associated with entities.
28type SourceCodeInfo interface {
29	// Location returns the SourceCodeInfo_Location from the file descriptor.
30	Location() *descriptor.SourceCodeInfo_Location
31
32	// LeadingComments returns any comment immediately preceding the entity,
33	// without any whitespace between it and the comment.
34	LeadingComments() string
35
36	// LeadingDetachedComments returns each comment block or line above the
37	// entity but separated by whitespace.
38	LeadingDetachedComments() []string
39
40	// TrailingComments returns any comment immediately following the entity,
41	// without any whitespace between it and the comment. If the comment would be
42	// a leading comment for another entity, it won't be considered a trailing
43	// comment.
44	TrailingComments() string
45}
46
47type sci struct {
48	desc *descriptor.SourceCodeInfo_Location
49}
50
51func (info sci) Location() *descriptor.SourceCodeInfo_Location { return info.desc }
52func (info sci) LeadingComments() string                       { return info.desc.GetLeadingComments() }
53func (info sci) LeadingDetachedComments() []string             { return info.desc.GetLeadingDetachedComments() }
54func (info sci) TrailingComments() string                      { return info.desc.GetTrailingComments() }
55
56var _ SourceCodeInfo = sci{}
57