Skip to content

Commit 309b59e

Browse files
authored
fix(internal/godocfx): only put TOC status on mod if all pkgs have same status (#4974)
1 parent 3441e1f commit 309b59e

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

internal/godocfx/parse.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,9 +543,23 @@ func processExamples(exs []*doc.Example, fset *token.FileSet) []example {
543543
func buildTOC(mod string, pis []pkgload.Info, extraFiles []extraFile) tableOfContents {
544544
toc := tableOfContents{}
545545

546+
// If all of the packages have the same status, only put the status on
547+
// the module instead of all of the individual packages.
548+
uniqueStatuses := map[string]struct{}{}
549+
for _, pi := range pis {
550+
uniqueStatuses[pi.Status] = struct{}{}
551+
}
552+
modStatus := ""
553+
if len(uniqueStatuses) == 1 {
554+
for status := range uniqueStatuses {
555+
modStatus = status
556+
}
557+
}
558+
546559
modTOC := &tocItem{
547-
UID: mod,
548-
Name: mod,
560+
UID: mod,
561+
Name: mod,
562+
Status: modStatus,
549563
}
550564

551565
for _, ef := range extraFiles {
@@ -563,10 +577,14 @@ func buildTOC(mod string, pis []pkgload.Info, extraFiles []extraFile) tableOfCon
563577
importPath := pi.Doc.ImportPath
564578
if importPath == mod {
565579
// Add the module root package immediately with the full name.
580+
rootPkgStatus := pi.Status
581+
if modStatus != "" {
582+
rootPkgStatus = ""
583+
}
566584
modTOC.addItem(&tocItem{
567585
UID: mod,
568586
Name: mod,
569-
Status: pi.Status,
587+
Status: rootPkgStatus,
570588
})
571589
continue
572590
}
@@ -575,7 +593,9 @@ func buildTOC(mod string, pis []pkgload.Info, extraFiles []extraFile) tableOfCon
575593
}
576594
trimmed := strings.TrimPrefix(importPath, mod+"/")
577595
trimmedPkgs = append(trimmedPkgs, trimmed)
578-
statuses[trimmed] = pi.Status
596+
if modStatus == "" {
597+
statuses[trimmed] = pi.Status
598+
}
579599
}
580600

581601
sort.Strings(trimmedPkgs)

0 commit comments

Comments
 (0)