cmd/viewer: add field comments to generated view methods

Extract field comments from AST and include them in generated view
methods. Comments are preserved from the original struct fields to
provide documentation for the view accessors.

Fixes #16958

Signed-off-by: Maisem Ali <3953239+maisem@users.noreply.github.com>
This commit is contained in:
Maisem Ali
2025-08-27 00:06:28 -07:00
committed by Brad Fitzpatrick
parent 80f5a00e76
commit 882b05fff9
10 changed files with 1383 additions and 245 deletions
+2 -1
View File
@@ -53,6 +53,7 @@ func TestViewerImports(t *testing.T) {
if err != nil {
t.Fatal(err)
}
var fieldComments map[fieldNameKey]string // don't need it for this test.
var output bytes.Buffer
tracker := codegen.NewImportTracker(pkg)
@@ -65,7 +66,7 @@ func TestViewerImports(t *testing.T) {
if !ok {
t.Fatalf("%q is not a named type", tt.typeNames[i])
}
genView(&output, tracker, namedType, pkg)
genView(&output, tracker, namedType, fieldComments)
}
for _, pkg := range tt.wantImports {