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

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>
This commit is contained in:
Colby Mchenry
2026-10-19 21:01:42 +00:00
committed by GitHub
parent f43432c86a
commit 6e68a11beb
5 changed files with 173 additions and 2 deletions
+5 -1
View File
@@ -697,11 +697,15 @@ impl<'t> Walker<'t> {
None
};
let signature = value_node.map(|v| util::init_signature(self.text(v)));
// A member of a `const ( … )` group has its own doc
// comment beside it in the parentheses; one without keeps
// the group's.
let doc = self.docstring_of(spec).or_else(|| docstring.clone());
var_row = self.create_node(
if is_const_decl { "constant" } else { "variable" },
&name,
spec,
Extra { docstring: docstring.clone(), signature, ..Extra::default() },
Extra { docstring: doc, signature, ..Extra::default() },
);
}
}