Skip to content

Commit 48a0217

Browse files
authored
fix(godocfx): shorten function names (#2880)
After this change, function headers show up as `func Foo` rather than `func Foo(s string) string`, matching the behavior of pkg.go.dev.
1 parent 8728cdf commit 48a0217

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

internal/godocfx/parse.go

+7-13
Original file line numberDiff line numberDiff line change
@@ -241,50 +241,44 @@ func parse(glob string) (map[string]*page, tableOfContents, *packages.Module, er
241241
for _, fn := range t.Funcs {
242242
fnUID := uid + "." + fn.Name
243243
pkgItem.addChild(child(fnUID))
244-
s := pkgsite.Synopsis(pkg.Fset, fn.Decl)
245244
pkgPage.addItem(&item{
246245
UID: fnUID,
247-
Name: s,
246+
Name: fmt.Sprintf("func %s\n", fn.Name),
248247
ID: fn.Name,
249248
Parent: uid,
250249
Type: "function",
251250
Summary: fn.Doc,
252251
Langs: onlyGo,
253-
// Note: Name has the syntax already.
254-
// Syntax: Syntax{Content: s},
252+
Syntax: syntax{Content: pkgsite.Synopsis(pkg.Fset, fn.Decl)},
255253
})
256254
}
257255
for _, fn := range t.Methods {
258256
fnUID := uid + "." + fn.Name
259257
pkgItem.addChild(child(fnUID))
260-
s := pkgsite.Synopsis(pkg.Fset, fn.Decl)
261258
pkgPage.addItem(&item{
262259
UID: fnUID,
263-
Name: s,
260+
Name: fmt.Sprintf("func (%s) %s\n", fn.Recv, fn.Name),
264261
ID: fn.Name,
265262
Parent: uid,
266-
Type: "function",
263+
Type: "function", // Note: this is actually a method.
267264
Summary: fn.Doc,
268265
Langs: onlyGo,
269-
// Note: Name has the syntax already.
270-
// Syntax: Syntax{Content: s},
266+
Syntax: syntax{Content: pkgsite.Synopsis(pkg.Fset, fn.Decl)},
271267
})
272268
}
273269
}
274270
for _, fn := range docPkg.Funcs {
275271
uid := pkg.PkgPath + "." + fn.Name
276272
pkgItem.addChild(child(uid))
277-
s := pkgsite.Synopsis(pkg.Fset, fn.Decl)
278273
pkgPage.addItem(&item{
279274
UID: uid,
280-
Name: s,
275+
Name: fmt.Sprintf("func %s\n", fn.Name),
281276
ID: fn.Name,
282277
Parent: pkg.PkgPath,
283278
Type: "function",
284279
Summary: fn.Doc,
285280
Langs: onlyGo,
286-
// Note: Name has the syntax already.
287-
// Syntax: Syntax{Content: s},
281+
Syntax: syntax{Content: pkgsite.Synopsis(pkg.Fset, fn.Decl)},
288282
})
289283
}
290284
}

0 commit comments

Comments
 (0)