@@ -129,16 +129,21 @@ func getCompositeLitRelatedComments(stack []ast.Node, cm ast.CommentMap) []*ast.
129
129
for i := len (stack ) - 1 ; i >= 0 ; i -- {
130
130
node := stack [i ]
131
131
132
- switch node .(type ) {
133
- case * ast.CompositeLit , // stack[len(stack)-1]
134
- * ast.ReturnStmt , // return ...
135
- * ast.IndexExpr , // map[enum]...{...}[key]
136
- * ast.CallExpr , // myfunc(map...)
137
- * ast.UnaryExpr , // &map...
138
- * ast.AssignStmt , // variable assignment (without var keyword)
139
- * ast.DeclStmt , // var declaration, parent of *ast.GenDecl
140
- * ast.GenDecl , // var declaration, parent of *ast.ValueSpec
141
- * ast.ValueSpec , // var declaration
132
+ switch tn := node .(type ) {
133
+ case * ast.CompositeLit :
134
+ // comments on the lines prior to literal
135
+ comments = append (comments , cm [node ]... )
136
+ // comments on the same line as literal type definition
137
+ // worth noting that event "typeless" literals have a type
138
+ comments = append (comments , cm [tn .Type ]... )
139
+ case * ast.ReturnStmt , // return ...
140
+ * ast.IndexExpr , // map[enum]...{...}[key]
141
+ * ast.CallExpr , // myfunc(map...)
142
+ * ast.UnaryExpr , // &map...
143
+ * ast.AssignStmt , // variable assignment (without var keyword)
144
+ * ast.DeclStmt , // var declaration, parent of *ast.GenDecl
145
+ * ast.GenDecl , // var declaration, parent of *ast.ValueSpec
146
+ * ast.ValueSpec , // var declaration
142
147
* ast.KeyValueExpr : // field declaration
143
148
comments = append (comments , cm [node ]... )
144
149
0 commit comments