Skip to content

Commit 9125731

Browse files
committed
*: add file path
1 parent cb5896a commit 9125731

File tree

5 files changed

+180
-166
lines changed

5 files changed

+180
-166
lines changed

parse/markdown.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (p *Proto) Markdown(title string, parseOpts []ParseOption, lopts ...string)
4141
switch opt {
4242
case ParseService:
4343
for _, svs := range p.Services {
44-
buf.WriteString(fmt.Sprintf("##### service `%s`\n\n", svs.Name))
44+
buf.WriteString(fmt.Sprintf("##### service `%s` (%s)\n\n", svs.Name, svs.FilePath))
4545
if svs.Description != "" {
4646
buf.WriteString(svs.Description)
4747
buf.WriteString("\n\n")
@@ -65,7 +65,7 @@ func (p *Proto) Markdown(title string, parseOpts []ParseOption, lopts ...string)
6565

6666
case ParseMessage:
6767
for _, msg := range p.Messages {
68-
buf.WriteString(fmt.Sprintf("##### message `%s`\n\n", msg.Name))
68+
buf.WriteString(fmt.Sprintf("##### message `%s` (%s)\n\n", msg.Name, msg.FilePath))
6969
if msg.Description != "" {
7070
buf.WriteString(msg.Description)
7171
buf.WriteString("\n\n")

parse/parse.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ func ReadFile(fpath string) (*Proto, error) {
9191
if err != nil {
9292
return nil, err
9393
}
94+
var (
95+
wd, _ = os.Getwd()
96+
fs = fpath
97+
)
98+
if strings.HasPrefix(fs, wd) {
99+
fs = strings.Replace(fs, wd, "", 1)
100+
if strings.HasPrefix(fs, "/") {
101+
fs = strings.Replace(fs, "/", "", 1)
102+
}
103+
}
94104

95105
lines, err := readLines(f)
96106
if err != nil {
@@ -161,6 +171,7 @@ func ReadFile(fpath string) (*Proto, error) {
161171

162172
case parsingMessage:
163173
if strings.HasSuffix(line, "}") { // closing of message
174+
protoMessage.FilePath = fs
164175
rp.Messages = append(rp.Messages, protoMessage)
165176
protoMessage = ProtoMessage{}
166177
comments = []string{}
@@ -214,6 +225,7 @@ func ReadFile(fpath string) (*Proto, error) {
214225
protoService.Methods = append(protoService.Methods, protoMethod)
215226
comments = []string{}
216227
} else if !strings.HasSuffix(line, "{}") && strings.HasSuffix(line, "}") { // closing of service
228+
protoService.FilePath = fs
217229
rp.Services = append(rp.Services, protoService)
218230
protoService = ProtoService{}
219231
comments = []string{}

parse/proto.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func (p *Proto) Sort() {
4242
// ProtoService represents the 'service' type in Protocol Buffer.
4343
// (https://developers.google.com/protocol-buffers/docs/proto3#services)
4444
type ProtoService struct {
45+
FilePath string
4546
Name string
4647
Description string
4748
Methods []ProtoMethod
@@ -58,6 +59,7 @@ type ProtoMethod struct {
5859
// ProtoMessage represents the 'message' type in Protocol Buffer.
5960
// (https://developers.google.com/protocol-buffers/docs/proto3#simple)
6061
type ProtoMessage struct {
62+
FilePath string
6163
Name string
6264
Description string
6365
Fields []ProtoField

0 commit comments

Comments
 (0)