Skip to content

fix(go): a constant in a const ( … ) group keeps its own doc comment - #2680

Merged
colbymchenry merged 2 commits into
mainfrom
claude/go-grouped-const-docs
Oct 19, 2026
Merged

colbymchenry merged 2 commits into
mainfrom
claude/go-grouped-const-docs

Conversation

@colbymchenry

Copy link
Copy Markdown
Owner

Follow-up to #2678 and #2679. A constant declared inside a const ( … ) group lost the doc comment written above it:

const (
	// ErrorTypeBind is used when Context.Bind() fails.
	ErrorTypeBind ErrorType = 1 << 63
	// ErrorTypeRender is used when Context.Render() fails.
	ErrorTypeRender ErrorType = 1 << 62

gin's ErrorTypeBind had no docstring. Both extractors read every member's docstring from the comment above const (, the group's, and never from the member's own comment. That is the comment go doc prints beside the member, and the one gopls shows on hover.

Change

Verification

A/B on real repos

main f43432c 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 the same ones:

repo gained their own doc (had none) own doc replaces the group's
etcd 113 0
prometheus 202 13
gin 10 3
  • Every change equals the member's own doc comment as go doc reads it, taken from the file: the comment-only lines right above the member, with no blank line and with directives left out.
  • Full check of every grouped constant against "own doc comment, else the group's" (580 / 1,475 / 82 members): main disagrees on 113 / 215 / 13, this branch on 0 / 0 / 0. The members with only a group doc (8 / 114 / 39) and with none (459 / 1,146 / 30) are unchanged.
  • Examples: prometheus FloatChunkEncodingXOR ("selects standard XOR encoding for float chunks"); prometheus lintErrExitCode; etcd's deprecated authpb.READ / WRITE aliases; and the generated const _ = protoimpl.EnforceVersion(…) guards ("Verify that this generated code is sufficiently up-to-date").
  • Kernel parity (kernel-parity.mjs --lang go): 0 diffs on all three repos. etcd 1065/1105, the same 40 erroring files deferred as on main; prometheus 746/746; gin 99/99.
  • Cost: one extra preceding-comment walk per constant; no measurable change.

Notes

  • Next, and last, follow-up as its own PR: variables declared in a var ( … ) block are not indexed at all. tree-sitter-go wraps a var group's specs in a var_spec_list node, which neither extractor reads, so etcd, prometheus and gin index no grouped variable. That PR gives them their own docs the same way.

🤖 Generated with Claude Code

colbymchenry and others added 2 commits October 19, 2026 15:48
Both extractors read every member's docstring from the comment above
`const (`, which documents the group. A constant documented inside the
group, like gin's ErrorTypeBind under "ErrorTypeBind is used when
Context.Bind() fails.", stored no docstring, or the group's comment
instead of its own.

A member's own doc comment, read with Go's doc comment rules, is now its
docstring. A member without one keeps the group's comment, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant