diff options
| author | Jeff Carr <[email protected]> | 2025-03-29 09:43:24 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-03-29 09:43:24 -0500 |
| commit | 0a97886cd2e942070ac478b2802f49dca8249f36 (patch) | |
| tree | d76ea1d019b3a57faac3454ba6a7e9e80a3a3526 /protoReformat.go | |
| parent | de7d698e194c69df2a884a62fe606d28b1ff7b71 (diff) | |
fix --debug
Diffstat (limited to 'protoReformat.go')
| -rw-r--r-- | protoReformat.go | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/protoReformat.go b/protoReformat.go index 4248ed9..efd568b 100644 --- a/protoReformat.go +++ b/protoReformat.go @@ -18,6 +18,7 @@ import ( var allTheLines *LinesScanner +/* type EnumMessage struct { msgPB *FormatMsg all []Message @@ -44,6 +45,7 @@ type Message interface { load() addMsg(Message) } +*/ func protoReformatComments(filename string) error { // read in the .proto file @@ -137,6 +139,7 @@ func doParse(lines []string) *FormatMsg { if strings.HasPrefix(line, "oneof ") { newmsg := basemsg.newOneofMessage(line) + comments = strings.TrimSpace(comments) newmsg.Notes = strings.Split(comments, "\n") comments = "" newmsg.load() @@ -146,6 +149,7 @@ func doParse(lines []string) *FormatMsg { if strings.HasPrefix(line, "enum ") { newmsg := basemsg.newEnumMessage(line) + comments = strings.TrimSpace(comments) newmsg.Notes = strings.Split(comments, "\n") comments = "" newmsg.load() @@ -157,6 +161,7 @@ func doParse(lines []string) *FormatMsg { log.Info("got to message", line) newmsg := basemsg.newStdMessage(line) + comments = strings.TrimSpace(comments) newmsg.Notes = strings.Split(comments, "\n") comments = "" newmsg.load() @@ -227,9 +232,11 @@ func (msgPB *FormatMsg) newEnumMessage(header string) *FormatMsg { // func loadMsgDefinition(msg *StdMessage) { // func (newMsg *EnumMessage) load() { // func (msg *StdMessage) loadMsgDefinition(msg *StdMessage) { +/* func (msg *StdMessage) load() { msg.msgPB.load() } +*/ func (msg *FormatMsg) load() { // fmtmsg := msg.msgPB @@ -416,13 +423,16 @@ func (all *FormatMsg) format() []string { func formatMessage(curmsg *FormatMsg) []string { var newmsg []string - // print the Notes - for _, line := range curmsg.Notes { - newmsg = append(newmsg, line) - } + // add the notes & comments before the header + newmsg = append(newmsg, strings.TrimSpace(strings.Join(curmsg.Notes, "\n"))) if curmsg.Header != "" { - line := fmt.Sprintf("%s%s // msg depth=%d", curmsg.padBase(), curmsg.Header, curmsg.Depth) + var line string + if argv.Debug { + line = fmt.Sprintf("%s%s // msg depth=%d", curmsg.padBase(), curmsg.Header, curmsg.Depth) + } else { + line = fmt.Sprintf("%s%s", curmsg.padBase(), curmsg.Header) + } parts := strings.Fields(line) if len(parts) > 3 { // hack to actually indent comments on the message line itself. you're welcome @@ -430,10 +440,19 @@ func formatMessage(curmsg *FormatMsg) []string { end := strings.Join(parts[3:], " ") offset := int(curmsg.MaxVarname) + int(curmsg.MaxVartype) + 16 - len(start) pad := fmt.Sprintf("%d", offset) - hmm := "%s %" + pad + "s %s // depth=%d" - line = fmt.Sprintf(hmm, start, " ", end, curmsg.Depth) + if argv.Debug { + hmm := "%s %" + pad + "s %s // depth=%d" + line = fmt.Sprintf(hmm, start, " ", end, curmsg.Depth) + } else { + hmm := "%s %" + pad + "s %s" + line = fmt.Sprintf(hmm, start, " ", end) + } } else { - line = fmt.Sprintf("%s // len(parts)=%d depth=%d", line, len(parts), curmsg.Depth) + if argv.Debug { + line = fmt.Sprintf("%s // len(parts)=%d depth=%d", line, len(parts), curmsg.Depth) + } else { + // line = fmt.Sprintf("%s test", line) + } } newmsg = append(newmsg, line) // " //header") } else { |
