Repository navigation
fix(go): a comment a blank line separates from a declaration is not its doc - #2678
Merged
Merged
Conversation
…ts doc Go's doc comment, the one go doc shows (go/parser's lead comment), is the comment group that ends on the line right above a declaration: comments on consecutive lines form one group, and a blank line ends it. Both extractors joined every comment above a Go declaration instead, so a section banner, a TODO or commented-out code above a blank line became part of the declaration's docstring, or its whole docstring when the declaration had no doc of its own. Go now keeps only that group, through a Go-only extractor option beside the trailing-comment one (docstringSkipsDetachedComments in TS, preceding_docstring_skipping_trailing_and_detached in the kernel). A comment that ends on the declaration's own line documents nothing, as in go doc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Go's doc comment, the one
go doc, pkg.go.dev and gopls show (go/parser's lead comment), is only the comment group that ends on the line right above a declaration: comments on consecutive lines form one group, and a blank line ends it. Both extractors joined every comment above a Go declaration instead. A section banner, a TODO, a lint line or commented-out code above a blank line was put in front of the declaration's docstring, or became its whole docstring when the declaration had none of its own:Context.Next:"/\nFLOW CONTROL\n/\nNext should be used only inside middleware.…"becomes"Next should be used only inside middleware.…"(seven ginContextmethods carried such a banner)TestTreeTrailingSlashRedirect: a commented-outfunc TestTreeDuplicateWildcard(t *testing.T) {…}becomes no docstringReadTx: an orphaned copy ofIsSafeRangeBucket's doc, a blank line abovetype ReadTx interface, becomes no docstringDecision. Go docstrings now follow go doc exactly (this chat's open question, settled with go doc as the oracle). Other languages keep joining every comment above a declaration.
Change
docstringSkipsDetachedCommentsin TS (getPrecedingDocstring's newskipDetached), andpreceding_docstring_skipping_trailing_and_detachedin the kernel. The kernel function replacespreceding_docstring_skipping_trailing, whose only caller was Go.consumeCommentGroup(1)grouping plus itsendline+1 == linelead test./* x */ func f() {}) documents nothing, as in go doc.typedeclarations) andconst/vardeclarations.Verification
__tests__/go-detached-doc-comments.test.ts, kernel and wasm, each on LF and CRLF:const/var, a type group's members, a block comment with a blank line inside, a two-paragraph//doc, a line+block+line group,/* x */ func f(), and a doc right under a trailing comment.skips_the_comments_a_blank_line_detaches. The trailing-comment unit test now calls the shared helper directly. All 5 docstring unit tests pass.torture.goparity fixture gains a detached banner and a banner above a doc;kernel-tsjs-paritypasses 96/96, CRLF cases included. fix(go): a type declared on its own keeps its doc comment #2438'sgo-type-doc-comments.test.tsis unchanged and passes.CODEGRAPH_KERNEL_EXPECT=1(--maxWorkers=4 --minWorkers=1): 7,505 passed, 0 failed, 80 skipped (7,585 tests, 0 failed files).A/B on real repos
main 22d420e vs this branch; etcd 6782f522, prometheus 0b57789d, gin 0f09c3a9.
Nodes, edges, unresolved refs and files are byte-identical on all three repos, on both the kernel and wasm paths. Only docstrings change, and the two paths change exactly the same ones:
func/type/const/vardeclaration (12,117 / 14,332 / 1,738 Go declarations): main disagrees with go doc on 19 / 31 / 16 of them, this branch on 0 / 0 / 0.revive:enablelint lines;go test -vcommand lines;LazyCluster,mmapSize,isOpenEnded; prometheus tritonDiscovery.refresh,TestBucketIterator. go doc doesn't show these either.kernel-parity.mjs --lang go), same on both arms:example_*_test.gofiles defer to wasm as on main);Notes
type ( … )group the group's doc. fix(go): a type declared on its own keeps its doc comment #2438 keeps the group comment off members on purpose, and this PR doesn't change that.//nolint:unparam,//go:embed testdata,//revive:disable:var-naming): 18 docstrings on these repos, 8 of which are nothing but a directive;const/vardeclared inside aconst ( … )/var ( … )group loses its own doc comment (gin'sErrorTypeBind is used when Context.Bind() fails.is stored as nothing): 341 documented members on these repos.🤖 Generated with Claude Code