@@ -268,7 +268,7 @@ func (pkg *Package) packageDoc() {
268
268
pkg .newlines (2 ) // Guarantee blank line before the components.
269
269
pkg .valueSummary (pkg .doc .Consts )
270
270
pkg .valueSummary (pkg .doc .Vars )
271
- pkg .funcSummary (pkg .doc .Funcs )
271
+ pkg .funcSummary (pkg .doc .Funcs , false )
272
272
pkg .typeSummary ()
273
273
pkg .bugs ()
274
274
}
@@ -308,24 +308,44 @@ func (pkg *Package) valueSummary(values []*doc.Value) {
308
308
}
309
309
}
310
310
311
- // funcSummary prints a one-line summary for each function.
312
- func (pkg * Package ) funcSummary (funcs []* doc.Func ) {
311
+ // funcSummary prints a one-line summary for each function. Constructors
312
+ // are printed by typeSummary, below, and so can be suppressed here.
313
+ func (pkg * Package ) funcSummary (funcs []* doc.Func , showConstructors bool ) {
314
+ // First, identify the constructors. Don't bother figuring out if they're exported.
315
+ var isConstructor map [* doc.Func ]bool
316
+ if ! showConstructors {
317
+ isConstructor = make (map [* doc.Func ]bool )
318
+ for _ , typ := range pkg .doc .Types {
319
+ for _ , constructor := range typ .Funcs {
320
+ isConstructor [constructor ] = true
321
+ }
322
+ }
323
+ }
313
324
for _ , fun := range funcs {
314
325
decl := fun .Decl
315
326
// Exported functions only. The go/doc package does not include methods here.
316
327
if isExported (fun .Name ) {
317
- pkg .oneLineFunc (decl )
328
+ if ! isConstructor [fun ] {
329
+ pkg .oneLineFunc (decl )
330
+ }
318
331
}
319
332
}
320
333
}
321
334
322
- // typeSummary prints a one-line summary for each type.
335
+ // typeSummary prints a one-line summary for each type, followed by its constructors .
323
336
func (pkg * Package ) typeSummary () {
324
337
for _ , typ := range pkg .doc .Types {
325
338
for _ , spec := range typ .Decl .Specs {
326
339
typeSpec := spec .(* ast.TypeSpec ) // Must succeed.
327
340
if isExported (typeSpec .Name .Name ) {
328
341
pkg .oneLineTypeDecl (typeSpec )
342
+ // Now print the constructors.
343
+ for _ , constructor := range typ .Funcs {
344
+ if isExported (constructor .Name ) {
345
+ pkg .Printf (indent )
346
+ pkg .oneLineFunc (constructor .Decl )
347
+ }
348
+ }
329
349
}
330
350
}
331
351
}
@@ -453,8 +473,8 @@ func (pkg *Package) symbolDoc(symbol string) bool {
453
473
}
454
474
pkg .valueSummary (typ .Consts )
455
475
pkg .valueSummary (typ .Vars )
456
- pkg .funcSummary (typ .Funcs )
457
- pkg .funcSummary (typ .Methods )
476
+ pkg .funcSummary (typ .Funcs , true )
477
+ pkg .funcSummary (typ .Methods , true )
458
478
found = true
459
479
}
460
480
if ! found {
0 commit comments