@@ -51,15 +51,27 @@ func extractGoMod(path string) error {
51
51
return nil
52
52
}
53
53
54
+ type commentGroupIdxAllocator struct {
55
+ nextIdx int
56
+ }
57
+
58
+ func (cgIdxAlloc * commentGroupIdxAllocator ) nextCgIdx () int {
59
+ ret := cgIdxAlloc .nextIdx
60
+ cgIdxAlloc .nextIdx ++
61
+ return ret
62
+ }
63
+
54
64
func extractGoModFile (tw * trap.Writer , file * modfile.FileSyntax ) {
65
+ cgIdxAlloc := commentGroupIdxAllocator {0 }
66
+
55
67
for idx , stmt := range file .Stmt {
56
- extractGoModExpr (tw , stmt , tw .Labeler .FileLabel (), idx )
68
+ extractGoModExpr (tw , stmt , tw .Labeler .FileLabel (), idx , & cgIdxAlloc )
57
69
}
58
70
59
- extractGoModComments (tw , file , tw .Labeler .FileLabel ())
71
+ extractGoModComments (tw , file , tw .Labeler .FileLabel (), & cgIdxAlloc )
60
72
}
61
73
62
- func extractGoModExpr (tw * trap.Writer , expr modfile.Expr , parent trap.Label , idx int ) {
74
+ func extractGoModExpr (tw * trap.Writer , expr modfile.Expr , parent trap.Label , idx int , cgIdxAlloc * commentGroupIdxAllocator ) {
63
75
lbl := tw .Labeler .LocalID (expr )
64
76
65
77
var kind int
@@ -80,18 +92,18 @@ func extractGoModExpr(tw *trap.Writer, expr modfile.Expr, parent trap.Label, idx
80
92
for idx , tok := range expr .Token {
81
93
dbscheme .ModTokensTable .Emit (tw , tok , lbl , idx )
82
94
}
83
- extractGoModExpr (tw , & expr .LParen , lbl , 0 )
95
+ extractGoModExpr (tw , & expr .LParen , lbl , 0 , cgIdxAlloc )
84
96
for idx , line := range expr .Line {
85
- extractGoModExpr (tw , line , lbl , idx + 1 )
97
+ extractGoModExpr (tw , line , lbl , idx + 1 , cgIdxAlloc )
86
98
}
87
- extractGoModExpr (tw , & expr .RParen , lbl , len (expr .Line )+ 1 )
99
+ extractGoModExpr (tw , & expr .RParen , lbl , len (expr .Line )+ 1 , cgIdxAlloc )
88
100
default :
89
101
log .Fatalf ("unknown go.mod expression of type %T" , expr )
90
102
}
91
103
92
104
dbscheme .ModExprsTable .Emit (tw , lbl , kind , parent , idx )
93
105
94
- extractGoModComments (tw , expr , lbl )
106
+ extractGoModComments (tw , expr , lbl , cgIdxAlloc )
95
107
96
108
start , end := expr .Span ()
97
109
extractLocation (tw , lbl , start .Line , start .LineRune , end .Line , end .LineRune )
@@ -135,7 +147,7 @@ func lexMax(a1 int, a2 int, b1 int, b2 int) (int, int) {
135
147
}
136
148
}
137
149
138
- func extractGoModComments (tw * trap.Writer , expr modfile.Expr , exprlbl trap.Label ) {
150
+ func extractGoModComments (tw * trap.Writer , expr modfile.Expr , exprlbl trap.Label , cgIdxAlloc * commentGroupIdxAllocator ) {
139
151
comments := expr .Comment ()
140
152
141
153
if len (comments .Before ) == 0 && len (comments .Suffix ) == 0 && len (comments .After ) == 0 {
@@ -144,7 +156,7 @@ func extractGoModComments(tw *trap.Writer, expr modfile.Expr, exprlbl trap.Label
144
156
145
157
// extract a pseudo `@commentgroup` for each expr that contains their associated comments
146
158
grouplbl := tw .Labeler .LocalID (GoModExprCommentWrapper {expr })
147
- dbscheme .CommentGroupsTable .Emit (tw , grouplbl , tw .Labeler .FileLabel (), 0 )
159
+ dbscheme .CommentGroupsTable .Emit (tw , grouplbl , tw .Labeler .FileLabel (), cgIdxAlloc . nextCgIdx () )
148
160
dbscheme .DocCommentsTable .Emit (tw , exprlbl , grouplbl )
149
161
150
162
var allComments []modfile.Comment
0 commit comments