summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile14
-rw-r--r--example/Makefile3
-rw-r--r--protoReformat.go74
3 files changed, 68 insertions, 23 deletions
diff --git a/Makefile b/Makefile
index 9093572..b15cd9a 100644
--- a/Makefile
+++ b/Makefile
@@ -17,6 +17,7 @@ help: build
test:
reset
make goimports vet build
+ git checkout example/fruit.proto
make -C example testGlobal
make -C example testProtoc
make -C example all
@@ -92,12 +93,19 @@ clean-more:
ls -l autogenpb autogenpb.last
-rm -f autogenpb.2*
-reformat-signal.proto-comments:
+reformat-signal.proto-reset:
+ git checkout example/*.proto
+
+reformat-signal.proto-comments: goimports vet build
git checkout example/fruit.proto
make -C example proto-reformat-restore
make -C example proto-reformat-comments
-reformat-signal.proto-full:
- git checkout example/fruit.proto
+reformat-signal.proto-full: goimports vet build
+ git checkout example/*.proto
make -C example proto-reformat-restore
make -C example proto-reformat-full
+
+reformat-signal.proto-fruit: goimports vet build
+ git checkout example/*.proto
+ make -C example proto-reformat-fruit
diff --git a/example/Makefile b/example/Makefile
index 52ee5c6..2947745 100644
--- a/example/Makefile
+++ b/example/Makefile
@@ -111,3 +111,6 @@ proto-reformat-comments:
proto-reformat-full:
autogenpb --proto signal.proto --format
+
+proto-reformat-fruit:
+ autogenpb --proto fruit.proto --format
diff --git a/protoReformat.go b/protoReformat.go
index 6afb93f..664e792 100644
--- a/protoReformat.go
+++ b/protoReformat.go
@@ -76,12 +76,12 @@ func protoReformat(filename string) error {
var newfile string
- var fmtmsg *FormatMsg
- fmtmsg = new(FormatMsg)
-
var bigName int64
var bigType int64
+ var fmtmsg *FormatMsg
+ fmtmsg = new(FormatMsg)
+
var inMessage bool
var allLinesIter iter.Seq[string]
allLinesIter = makeLineIter(data)
@@ -110,10 +110,15 @@ func protoReformat(filename string) error {
if !inMessage {
continue
}
- fmtmsg.Lines = append(fmtmsg.Lines, line)
}
- fmtmsg.MaxVarname = bigName
- fmtmsg.MaxVartype = bigType
+
+ var basemsg *FormatMsg
+ basemsg = new(FormatMsg)
+ basemsg.MaxVarname = bigName
+ basemsg.MaxVartype = bigType
+ inMessage = false
+
+ var comments string
// write out the messages
allTheLines = newLinesScanner(strings.Split(string(data), "\n"))
@@ -121,35 +126,59 @@ func protoReformat(filename string) error {
line := allTheLines.NextRaw()
if strings.HasPrefix(line, "oneof ") {
- newmsg := fmtmsg.newOneofMessage(line)
+ newmsg := basemsg.newOneofMessage(line)
+ newmsg.msgPB.Notes = strings.Split(comments, "\n")
newmsg.load()
- for _, newline := range newmsg.msgPB.format() {
- newfile += fmt.Sprintln(newline)
- }
+ basemsg.Msgs = append(basemsg.Msgs, newmsg.msgPB)
+ /*
+ for _, newline := range newmsg.msgPB.format() {
+ newfile += fmt.Sprintln(newline)
+ }
+ */
+ inMessage = true
continue
}
if strings.HasPrefix(line, "enum ") {
- newmsg := fmtmsg.newEnumMessage(line)
+ newmsg := basemsg.newEnumMessage(line)
+ newmsg.msgPB.Notes = strings.Split(comments, "\n")
newmsg.load()
+ basemsg.Msgs = append(basemsg.Msgs, newmsg.msgPB)
// loadEnumDefinition(newmsg)
- for _, newline := range newmsg.msgPB.format() {
- newfile += fmt.Sprintln(newline)
- }
+ /*
+ for _, newline := range newmsg.msgPB.format() {
+ newfile += fmt.Sprintln(newline)
+ }
+ */
+ inMessage = true
continue
}
if strings.HasPrefix(line, "message ") {
- newmsg := fmtmsg.newStdMessage(line)
- newmsg.load()
log.Info("got to message", line)
- for _, newline := range newmsg.msgPB.format() {
- newfile += fmt.Sprintln(newline)
- }
+
+ newmsg := basemsg.newStdMessage(line)
+ newmsg.msgPB.Notes = strings.Split(comments, "\n")
+ newmsg.load()
+ basemsg.Msgs = append(basemsg.Msgs, newmsg.msgPB)
+ /*
+ for _, newline := range newmsg.msgPB.format() {
+ newfile += fmt.Sprintln(newline)
+ }
+ */
+ inMessage = true
continue
}
- newfile += fmt.Sprintln(line)
+ if inMessage {
+ comments += fmt.Sprintln(line)
+ } else {
+ basemsg.Notes = append(basemsg.Notes, line)
+ }
+ }
+
+ for _, newline := range basemsg.format() {
+ newfile += fmt.Sprintln(newline)
}
return saveFile(filename, newfile)
@@ -375,6 +404,11 @@ func (msg *FormatMsg) format() []string {
func formatMessage(curmsg *FormatMsg) []string {
var newmsg []string
+ // print the Notes
+ for _, line := range curmsg.Notes {
+ newmsg = append(newmsg, line)
+ }
+
if curmsg.Header != "" {
line := fmt.Sprintf("%s%s // msg depth=%d", curmsg.padBase(), curmsg.Header, curmsg.Depth)
parts := strings.Fields(line)