Skip to content

Commit eaea7f3

Browse files
committed
fix: knownTypes should only apply to imported types
knownTypes entries were being applied to all types regardless of whether they were local to the source package or imported from another package. This caused local types that appeared in knownTypes to be rendered with external links rather than local anchor links, breaking in-page navigation when rendered locally. Move the lookup inside the IsBasic/Imported branch so that it only applies to types that cannot resolve to a local anchor. Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent 27bb554 commit eaea7f3

2 files changed

Lines changed: 5 additions & 9 deletions

File tree

renderer/functions.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,10 @@ func (f *Functions) LinkForType(t *types.Type) (link string, local bool) {
7575
return f.LinkForKubeType(t), false
7676
}
7777

78-
if kt, ok := f.IsKnownType(t); ok {
79-
return f.LinkForKnownType(kt), false
80-
}
81-
8278
if t.IsBasic() || t.Imported {
79+
if kt, ok := f.IsKnownType(t); ok {
80+
return f.LinkForKnownType(kt), false
81+
}
8382
return "", false
8483
}
8584

renderer/functions_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,8 @@ func TestLinkForType(t *testing.T) {
5555
{
5656
name: "local type ignores knownTypes and gets local link",
5757
typ: &types.Type{Name: "Foo", Package: "example.com/pkg", Imported: false},
58-
// FIXME: This is incorrect and should be a relative link
59-
// wantLink: "example-com-pkg-foo",
60-
// wantLocal: true,
61-
wantLink: "https://example.com/docs#foo",
62-
wantLocal: false,
58+
wantLink: "example-com-pkg-foo",
59+
wantLocal: true,
6360
},
6461
{
6562
name: "kube type gets kubernetes.io link even when also in knownTypes",

0 commit comments

Comments
 (0)