(comments []Comment)
| 49 | } |
| 50 | |
| 51 | func coalesce(comments []Comment) []Comment { |
| 52 | var joined []Comment |
| 53 | |
| 54 | tBuf := bytes.Buffer{} |
| 55 | sBuf := bytes.Buffer{} |
| 56 | |
| 57 | for i, comment := range comments { |
| 58 | if comment.Scope == "text.comment.block" { //nolint:gocritic |
| 59 | joined = append(joined, comment) |
| 60 | } else if i == 0 || doneMerging(comment, comments[i-1]) { |
| 61 | if tBuf.Len() > 0 { |
| 62 | // We have comments to merge ... |
| 63 | last := joined[len(joined)-1] |
| 64 | |
| 65 | last.Text += addSourceLine(tBuf.String(), false) |
| 66 | last.Source += addSourceLine(sBuf.String(), false) |
| 67 | |
| 68 | joined[len(joined)-1] = last |
| 69 | |
| 70 | tBuf.Reset() |
| 71 | sBuf.Reset() |
| 72 | } |
| 73 | joined = append(joined, comment) |
| 74 | } else { |
| 75 | tBuf.WriteString(addSourceLine(comment.Text, true)) |
| 76 | sBuf.WriteString(addSourceLine(comment.Source, true)) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | if tBuf.Len() > 0 { |
| 81 | last := joined[len(joined)-1] |
| 82 | |
| 83 | last.Text += addSourceLine(tBuf.String(), false) |
| 84 | last.Source += addSourceLine(sBuf.String(), false) |
| 85 | |
| 86 | joined[len(joined)-1] = last |
| 87 | |
| 88 | tBuf.Reset() |
| 89 | sBuf.Reset() |
| 90 | } |
| 91 | |
| 92 | for i, comment := range joined { |
| 93 | joined[i].Text = strings.TrimLeft(comment.Text, " ") |
| 94 | } |
| 95 | |
| 96 | return joined |
| 97 | } |
| 98 | |
| 99 | // GetComments returns all comments in the given source code. |
| 100 | func GetComments(source []byte, lang *Language) ([]Comment, error) { |
no test coverage detected
searching dependent graphs…