summaryrefslogtreecommitdiff
path: root/protoReformat.go
diff options
context:
space:
mode:
Diffstat (limited to 'protoReformat.go')
-rw-r--r--protoReformat.go62
1 files changed, 8 insertions, 54 deletions
diff --git a/protoReformat.go b/protoReformat.go
index af64f87..1f04680 100644
--- a/protoReformat.go
+++ b/protoReformat.go
@@ -17,6 +17,7 @@ import (
// like 'goimport', but for .proto files
var allTheLines *LinesScanner
+var allTheNewLines []string
/*
type EnumMessage struct {
@@ -67,43 +68,6 @@ func protoReformat(filename string) error {
var newfile string
- // var bigName int64
- // var bigType int64
-
- // var fmtmsg *FormatMsg
- // fmtmsg = new(FormatMsg)
-
- /*
- var allLinesIter iter.Seq[string]
- allLinesIter = makeLineIter(data)
- // gets the max vartype and varname
- for line := range allLinesIter {
- if strings.HasPrefix(line, "message ") {
- inMessage = true
- continue
- }
-
- // find the end of the message
- if strings.HasPrefix(line, "}") {
- inMessage = false
- setMaxSizes(fmtmsg)
- if bigName < fmtmsg.MaxVarname {
- bigName = fmtmsg.MaxVarname
- }
- if bigType < fmtmsg.MaxVartype {
- bigType = fmtmsg.MaxVartype
- }
- fmtmsg = new(FormatMsg)
- continue
- }
-
- // don't format or change anything when not in a "message {" section
- if !inMessage {
- continue
- }
- }
- */
-
basemsg := doParse(strings.Split(string(data), "\n"))
for _, newline := range basemsg.format() {
@@ -301,21 +265,6 @@ func makeLineIter(data []byte) iter.Seq[string] {
}
}
-/*
-// func loadEnumDefinition(newMsg *EnumMessage) *EnumMessage {
-func (newMsg *EnumMessage) load() {
- curPB := newMsg.msgPB
- for allTheLines.Scan() {
- line := allTheLines.Next()
- if strings.HasPrefix(line, "}") {
- curPB.Footer = line
- return
- }
- curPB.Lines = append(curPB.Lines, line)
- }
-}
-*/
-
// find the max length of varname and vartype
func setMaxSizes(curmsg *FormatMsg) {
for _, line := range curmsg.Lines {
@@ -504,13 +453,18 @@ func formatMessage(curmsg *FormatMsg) []string {
mt := fmt.Sprintf("%d", curmsg.MaxVartype)
mv := fmt.Sprintf("%d", curmsg.MaxVarname)
- hmm := " %-" + mt + "s %-" + mv + "s = %-3s %s"
+ hmm := "%s%-" + mt + "s %-" + mv + "s = %-3s %s"
vartype, varname, id, end := tokenMsgVar(line)
end = strings.TrimSpace(end)
id = id + ";"
- newline := fmt.Sprintf(hmm, vartype, varname, id, end)
+ var newline string
+ if argv.Debug {
+ newline = fmt.Sprintf(hmm+" //depth=%d", curmsg.padding(0), vartype, varname, id, end, curmsg.Depth)
+ } else {
+ newline = fmt.Sprintf(hmm, curmsg.padding(0), vartype, varname, id, end)
+ }
newline = strings.TrimRight(newline, " ")
newmsg = append(newmsg, newline)
}