From df70a7418b980965560c214e834f3e37c4bf19ea Mon Sep 17 00:00:00 2001 From: anatole Date: Mon, 5 Feb 2024 18:45:40 -0800 Subject: [PATCH] Extract Go comments from "main" package too ExtractGoComments() uses the fully-qualified package path when creating keys in our CommentMap, but we perform lookups in that map using keys constructed using (reflect.Type)PkgPath(). The latter method always returns "main" for types defined in the "main" package, rather than a fully-qualified package path, so those lookups fail. The result is that we never incorporate comments into a schema for types defined in "main". Update ExtractGoComments() to handle the special case of "main". --- comment_extractor.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/comment_extractor.go b/comment_extractor.go index e157837..4173d20 100644 --- a/comment_extractor.go +++ b/comment_extractor.go @@ -36,9 +36,12 @@ func ExtractGoComments(base, path string, commentMap map[string]string) error { if err != nil { return err } - for _, v := range d { + for pkg, v := range d { // paths may have multiple packages, like for tests k := gopath.Join(base, path) + if pkg == "main" { + k = pkg + } dict[k] = append(dict[k], v) } }