@@ -51,15 +51,27 @@ func extractGoMod(path string) error {
5151 return nil
5252}
5353
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+
5464func extractGoModFile (tw * trap.Writer , file * modfile.FileSyntax ) {
65+ cgIdxAlloc := commentGroupIdxAllocator {0 }
66+
5567 for idx , stmt := range file .Stmt {
56- extractGoModExpr (tw , stmt , tw .Labeler .FileLabel (), idx )
68+ extractGoModExpr (tw , stmt , tw .Labeler .FileLabel (), idx , & cgIdxAlloc )
5769 }
5870
59- extractGoModComments (tw , file , tw .Labeler .FileLabel ())
71+ extractGoModComments (tw , file , tw .Labeler .FileLabel (), & cgIdxAlloc )
6072}
6173
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 ) {
6375 lbl := tw .Labeler .LocalID (expr )
6476
6577 var kind int
@@ -80,18 +92,18 @@ func extractGoModExpr(tw *trap.Writer, expr modfile.Expr, parent trap.Label, idx
8092 for idx , tok := range expr .Token {
8193 dbscheme .ModTokensTable .Emit (tw , tok , lbl , idx )
8294 }
83- extractGoModExpr (tw , & expr .LParen , lbl , 0 )
95+ extractGoModExpr (tw , & expr .LParen , lbl , 0 , cgIdxAlloc )
8496 for idx , line := range expr .Line {
85- extractGoModExpr (tw , line , lbl , idx + 1 )
97+ extractGoModExpr (tw , line , lbl , idx + 1 , cgIdxAlloc )
8698 }
87- extractGoModExpr (tw , & expr .RParen , lbl , len (expr .Line )+ 1 )
99+ extractGoModExpr (tw , & expr .RParen , lbl , len (expr .Line )+ 1 , cgIdxAlloc )
88100 default :
89101 log .Fatalf ("unknown go.mod expression of type %T" , expr )
90102 }
91103
92104 dbscheme .ModExprsTable .Emit (tw , lbl , kind , parent , idx )
93105
94- extractGoModComments (tw , expr , lbl )
106+ extractGoModComments (tw , expr , lbl , cgIdxAlloc )
95107
96108 start , end := expr .Span ()
97109 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) {
135147 }
136148}
137149
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 ) {
139151 comments := expr .Comment ()
140152
141153 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
144156
145157 // extract a pseudo `@commentgroup` for each expr that contains their associated comments
146158 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 () )
148160 dbscheme .DocCommentsTable .Emit (tw , exprlbl , grouplbl )
149161
150162 var allComments []modfile.Comment
0 commit comments