Skip to content

Commit a1cd5a3

Browse files
committed
upd
1 parent da7af58 commit a1cd5a3

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

internal/godoc/dochtml/dochtml.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
"golang.org/x/pkgsite/internal"
3030
"golang.org/x/pkgsite/internal/derrors"
3131
"golang.org/x/pkgsite/internal/godoc/dochtml/internal/render"
32+
"golang.org/x/pkgsite/internal/log"
33+
"golang.org/x/pkgsite/internal/stdlib"
3234
"golang.org/x/text/cases"
3335
"golang.org/x/text/language"
3436
)
@@ -442,15 +444,21 @@ func buildNoteHeaders(notes map[string][]*doc.Note) map[string]noteHeader {
442444
}
443445

444446
// versionedPkgPath transforms package paths to contain the same version as the
445-
// current module if the package belongs to the module. As a special case,
446-
// versionedPkgPath will not add versions to standard library packages.
447+
// current module if the package belongs to the module.
447448
func versionedPkgPath(pkgPath string, modInfo *ModuleInfo) string {
448-
if modInfo == nil || !modInfo.ModulePackages[pkgPath] {
449+
if modInfo != nil && modInfo.ModulePath == "std" {
450+
tag, err := stdlib.TagForVersion(modInfo.ResolvedVersion)
451+
if err != nil {
452+
log.Errorf(context.TODO(), "goTagForVersion(%q): %v", modInfo.ResolvedVersion, err)
453+
return pkgPath
454+
}
455+
return fmt.Sprintf("%s@%s", pkgPath, tag)
456+
}
457+
458+
if modInfo == nil || (!modInfo.ModulePackages[pkgPath]) {
449459
return pkgPath
450460
}
451-
// We don't need to do anything special here for standard library packages
452-
// since pkgPath will never contain the "std/" module prefix, and
453-
// modInfo.ModulePackages contains this prefix for standard library packages.
461+
454462
innerPkgPath := pkgPath[len(modInfo.ModulePath):]
455463
return fmt.Sprintf("%s@%s%s", modInfo.ModulePath, modInfo.ResolvedVersion, innerPkgPath)
456464
}

internal/godoc/dochtml/dochtml_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -242,24 +242,24 @@ func TestVersionedPkgPath(t *testing.T) {
242242
want string
243243
}{
244244
{
245-
name: "builtin package is not versioned",
245+
name: "builtin package is versioned",
246246
pkgPath: "builtin",
247247
modInfo: &ModuleInfo{
248248
ModulePath: "std",
249-
ResolvedVersion: "v1.14.4",
249+
ResolvedVersion: "v1.14",
250250
ModulePackages: map[string]bool{"std/builtin": true, "std/net/http": true},
251251
},
252-
want: "builtin",
252+
want: "builtin@go1.14",
253253
},
254254
{
255-
name: "std packages are not versioned",
255+
name: "std packages are versioned",
256256
pkgPath: "net/http",
257257
modInfo: &ModuleInfo{
258258
ModulePath: "std",
259-
ResolvedVersion: "v1.14.4",
259+
ResolvedVersion: "v1.23.0",
260260
ModulePackages: map[string]bool{"std/builtin": true, "std/net/http": true},
261261
},
262-
want: "net/http",
262+
want: "net/http@go1.23.0",
263263
},
264264
{
265265
name: "imports from other modules are not versioned",

0 commit comments

Comments
 (0)