From 309b59e583d1bf0dd9ffe84223034eb8a2975d47 Mon Sep 17 00:00:00 2001 From: Tyler Bui-Palsulich <26876514+tbpg@users.noreply.github.com> Date: Mon, 11 Oct 2021 16:14:11 -0400 Subject: [PATCH] fix(internal/godocfx): only put TOC status on mod if all pkgs have same status (#4974) --- internal/godocfx/parse.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/internal/godocfx/parse.go b/internal/godocfx/parse.go index 884ac0b99a5..067208c91b8 100644 --- a/internal/godocfx/parse.go +++ b/internal/godocfx/parse.go @@ -543,9 +543,23 @@ func processExamples(exs []*doc.Example, fset *token.FileSet) []example { func buildTOC(mod string, pis []pkgload.Info, extraFiles []extraFile) tableOfContents { toc := tableOfContents{} + // If all of the packages have the same status, only put the status on + // the module instead of all of the individual packages. + uniqueStatuses := map[string]struct{}{} + for _, pi := range pis { + uniqueStatuses[pi.Status] = struct{}{} + } + modStatus := "" + if len(uniqueStatuses) == 1 { + for status := range uniqueStatuses { + modStatus = status + } + } + modTOC := &tocItem{ - UID: mod, - Name: mod, + UID: mod, + Name: mod, + Status: modStatus, } for _, ef := range extraFiles { @@ -563,10 +577,14 @@ func buildTOC(mod string, pis []pkgload.Info, extraFiles []extraFile) tableOfCon importPath := pi.Doc.ImportPath if importPath == mod { // Add the module root package immediately with the full name. + rootPkgStatus := pi.Status + if modStatus != "" { + rootPkgStatus = "" + } modTOC.addItem(&tocItem{ UID: mod, Name: mod, - Status: pi.Status, + Status: rootPkgStatus, }) continue } @@ -575,7 +593,9 @@ func buildTOC(mod string, pis []pkgload.Info, extraFiles []extraFile) tableOfCon } trimmed := strings.TrimPrefix(importPath, mod+"/") trimmedPkgs = append(trimmedPkgs, trimmed) - statuses[trimmed] = pi.Status + if modStatus == "" { + statuses[trimmed] = pi.Status + } } sort.Strings(trimmedPkgs)