Skip to content

Commit

Permalink
Generate const documentation.
Browse files Browse the repository at this point in the history
Fixes #340.
  • Loading branch information
psha- committed Oct 26, 2023
1 parent 744da80 commit 3d857d6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions bind/gen_varconst.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ func (g *pyGen) genConstValue(c *Const) {
val = "False"
}
g.pywrap.Printf("%s = %s\n", c.GoName(), val)
if c.doc != "" {
lns := strings.Split(c.doc, "\n")
g.pywrap.Printf(`"""`)
g.pywrap.Printf("\n")
for _, l := range lns {
g.pywrap.Printf("%s\n", l)
}
g.pywrap.Printf(`"""`)
g.pywrap.Printf("\n")
}
}

func (g *pyGen) genEnum(e *Enum) {
Expand Down
15 changes: 15 additions & 0 deletions bind/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,28 @@ func (p *Package) getDoc(parent string, o types.Object) string {
n := o.Name()
switch tp := o.(type) {
case *types.Const:
// Check for untyped consts
for _, c := range p.doc.Consts {
for _, cn := range c.Names {
if n == cn {
return c.Doc
}
}
}
// Check for typed consts
scopeName := p.pkg.Scope().Lookup(n)
constType := scopeName.Type()
for _, t := range p.doc.Types {
if p.pkg.Path()+"."+t.Name == constType.String() {
for _, c := range t.Consts {
for _, cn := range c.Names {
if n == cn {
return c.Doc
}
}
}
}
}

case *types.Var:
if tp.IsField() && parent != "" {
Expand Down

0 comments on commit 3d857d6

Please sign in to comment.