Skip to content

Commit

Permalink
Merge pull request #19 from g4s8/i18-unexported-types
Browse files Browse the repository at this point in the history
fix: proccess unexported type nodes
  • Loading branch information
g4s8 authored Apr 10, 2024
2 parents 4c4d50f + abb1822 commit f917c17
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
8 changes: 8 additions & 0 deletions _examples/unexported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

//go:generate go run ../ -output unexported.md
type appconfig struct {
// Port the application will listen on inside the container
Port int `env:"PORT" envDefault:"8080"`
// some more stuff I omitted here
}
6 changes: 6 additions & 0 deletions _examples/unexported.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Environment Variables

## appconfig

- `PORT` (default: `8080`) - Port the application will listen on inside the container

8 changes: 7 additions & 1 deletion ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ func (v *astVisitor) Walk(n ast.Node) {
}

func (v *astVisitor) Visit(n ast.Node) ast.Visitor {
if n == nil {
return nil
}

v.logger.Printf("ast(%d): visit node (%T)", v.depth, n)

if v.currentNode == nil {
v.currentNode = &visitorNode{kind: nodeRoot}
}
Expand Down Expand Up @@ -211,7 +217,7 @@ func fieldNamesToStr(f *ast.Field) []string {
}

func newASTTypeDocResolver(fileSet *token.FileSet, astFile *ast.File) (func(t *ast.TypeSpec) string, error) {
docs, err := doc.NewFromFiles(fileSet, []*ast.File{astFile}, "./", doc.PreserveAST)
docs, err := doc.NewFromFiles(fileSet, []*ast.File{astFile}, "./", doc.PreserveAST|doc.AllDecls)
if err != nil {
return nil, fmt.Errorf("extract package docs: %w", err)
}
Expand Down
11 changes: 11 additions & 0 deletions inspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,17 @@ func TestInspector(t *testing.T) {
},
},
},
{
name: "unexported.go",
typeName: "appconfig",
expect: []*EnvDocItem{
{
Name: "PORT",
Doc: "Port the application will listen on inside the container",
Opts: EnvVarOptions{Default: "8080"},
},
},
},
} {
scopes := c.expectScopes
if scopes == nil {
Expand Down
6 changes: 6 additions & 0 deletions testdata/unexported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package testdata

type appconfig struct {
// Port the application will listen on inside the container
Port int `env:"PORT" envDefault:"8080"`
}

0 comments on commit f917c17

Please sign in to comment.