From a1cd5a33cfb6f5ace09bf493401db54fd65ca12d Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Fri, 16 Aug 2024 15:15:35 -0700 Subject: [PATCH 1/3] upd --- internal/godoc/dochtml/dochtml.go | 20 ++++++++++++++------ internal/godoc/dochtml/dochtml_test.go | 12 ++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/internal/godoc/dochtml/dochtml.go b/internal/godoc/dochtml/dochtml.go index 74870daf8..aca76ff84 100644 --- a/internal/godoc/dochtml/dochtml.go +++ b/internal/godoc/dochtml/dochtml.go @@ -29,6 +29,8 @@ import ( "golang.org/x/pkgsite/internal" "golang.org/x/pkgsite/internal/derrors" "golang.org/x/pkgsite/internal/godoc/dochtml/internal/render" + "golang.org/x/pkgsite/internal/log" + "golang.org/x/pkgsite/internal/stdlib" "golang.org/x/text/cases" "golang.org/x/text/language" ) @@ -442,15 +444,21 @@ func buildNoteHeaders(notes map[string][]*doc.Note) map[string]noteHeader { } // versionedPkgPath transforms package paths to contain the same version as the -// current module if the package belongs to the module. As a special case, -// versionedPkgPath will not add versions to standard library packages. +// current module if the package belongs to the module. func versionedPkgPath(pkgPath string, modInfo *ModuleInfo) string { - if modInfo == nil || !modInfo.ModulePackages[pkgPath] { + if modInfo != nil && modInfo.ModulePath == "std" { + tag, err := stdlib.TagForVersion(modInfo.ResolvedVersion) + if err != nil { + log.Errorf(context.TODO(), "goTagForVersion(%q): %v", modInfo.ResolvedVersion, err) + return pkgPath + } + return fmt.Sprintf("%s@%s", pkgPath, tag) + } + + if modInfo == nil || (!modInfo.ModulePackages[pkgPath]) { return pkgPath } - // We don't need to do anything special here for standard library packages - // since pkgPath will never contain the "std/" module prefix, and - // modInfo.ModulePackages contains this prefix for standard library packages. + innerPkgPath := pkgPath[len(modInfo.ModulePath):] return fmt.Sprintf("%s@%s%s", modInfo.ModulePath, modInfo.ResolvedVersion, innerPkgPath) } diff --git a/internal/godoc/dochtml/dochtml_test.go b/internal/godoc/dochtml/dochtml_test.go index 617f4f7a3..a7ba2d05a 100644 --- a/internal/godoc/dochtml/dochtml_test.go +++ b/internal/godoc/dochtml/dochtml_test.go @@ -242,24 +242,24 @@ func TestVersionedPkgPath(t *testing.T) { want string }{ { - name: "builtin package is not versioned", + name: "builtin package is versioned", pkgPath: "builtin", modInfo: &ModuleInfo{ ModulePath: "std", - ResolvedVersion: "v1.14.4", + ResolvedVersion: "v1.14", ModulePackages: map[string]bool{"std/builtin": true, "std/net/http": true}, }, - want: "builtin", + want: "builtin@go1.14", }, { - name: "std packages are not versioned", + name: "std packages are versioned", pkgPath: "net/http", modInfo: &ModuleInfo{ ModulePath: "std", - ResolvedVersion: "v1.14.4", + ResolvedVersion: "v1.23.0", ModulePackages: map[string]bool{"std/builtin": true, "std/net/http": true}, }, - want: "net/http", + want: "net/http@go1.23.0", }, { name: "imports from other modules are not versioned", From ad9dafc09dab6b6a9bed2882dcd3b5f97ff5be44 Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Fri, 16 Aug 2024 16:16:51 -0700 Subject: [PATCH 2/3] nit --- internal/godoc/dochtml/dochtml.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/godoc/dochtml/dochtml.go b/internal/godoc/dochtml/dochtml.go index aca76ff84..df99411a4 100644 --- a/internal/godoc/dochtml/dochtml.go +++ b/internal/godoc/dochtml/dochtml.go @@ -446,7 +446,7 @@ func buildNoteHeaders(notes map[string][]*doc.Note) map[string]noteHeader { // versionedPkgPath transforms package paths to contain the same version as the // current module if the package belongs to the module. func versionedPkgPath(pkgPath string, modInfo *ModuleInfo) string { - if modInfo != nil && modInfo.ModulePath == "std" { + if modInfo != nil && modInfo.ModulePath == stdlib.ModulePath { tag, err := stdlib.TagForVersion(modInfo.ResolvedVersion) if err != nil { log.Errorf(context.TODO(), "goTagForVersion(%q): %v", modInfo.ResolvedVersion, err) From 9236b0f8eab572a047aa63e22b9bfa72483c41f0 Mon Sep 17 00:00:00 2001 From: Alex Bozhenko Date: Fri, 16 Aug 2024 16:25:36 -0700 Subject: [PATCH 3/3] nit --- internal/godoc/dochtml/dochtml.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/godoc/dochtml/dochtml.go b/internal/godoc/dochtml/dochtml.go index df99411a4..e6e00f373 100644 --- a/internal/godoc/dochtml/dochtml.go +++ b/internal/godoc/dochtml/dochtml.go @@ -455,7 +455,7 @@ func versionedPkgPath(pkgPath string, modInfo *ModuleInfo) string { return fmt.Sprintf("%s@%s", pkgPath, tag) } - if modInfo == nil || (!modInfo.ModulePackages[pkgPath]) { + if modInfo == nil || !modInfo.ModulePackages[pkgPath] { return pkgPath }