diff --git a/internal/gno/parser.go b/internal/gno/parser.go index acd289c..c5dbd36 100644 --- a/internal/gno/parser.go +++ b/internal/gno/parser.go @@ -226,15 +226,13 @@ func function(n *ast.FuncDecl, source string) *Symbol { } else { kind = "func" } - if n.Type.Results != nil && len(n.Type.Results.List) == 1 { - // Store retType only if there's only one - retType = n.Type.Results.List[0].Type.(*ast.Ident).Name - } + retType, params := typeFromNode(n.Type, source) return &Symbol{ Name: n.Name.Name, Doc: n.Doc.Text(), Signature: strings.Split(source[n.Pos()-1:n.End()-1], " {")[0], Kind: kind, + Fields: params, Recv: recv, Type: retType, } @@ -311,6 +309,13 @@ func typeFromNode(x ast.Node, source string) (string, []Symbol) { return typeFromNode(x.X, source) case *ast.StructType: // inline struct return "", symbolsFromFieldList(x.Fields, source) + case *ast.FuncType: + var retType string + if x.Results != nil && len(x.Results.List) == 1 { + // Store retType only if there's only one + retType = x.Results.List[0].Type.(*ast.Ident).Name + } + return retType, symbolsFromFieldList(x.Params, source) case *ast.InterfaceType: return "", symbolsFromFieldList(x.Methods, source) } diff --git a/internal/gno/testdata/parsePackages-func.txtar b/internal/gno/testdata/parsePackages-func.txtar index e8ca1c2..3a7f724 100644 --- a/internal/gno/testdata/parsePackages-func.txtar +++ b/internal/gno/testdata/parsePackages-func.txtar @@ -29,6 +29,27 @@ func i() x { "Name": "f", "Signature": "func f(x int, y interface{ Foo() int }) bool", "Kind": "func", + "Fields": [ + { + "Name": "x", + "Signature": "x int", + "Kind": "field", + "Type": "int" + }, + { + "Name": "y", + "Signature": "y interface{ Foo() int }", + "Kind": "field", + "Fields": [ + { + "Name": "Foo", + "Signature": "Foo() int", + "Kind": "method", + "Type": "int" + } + ] + } + ], "Type": "bool" }, { diff --git a/internal/gno/testdata/parsePackages-interface.txtar b/internal/gno/testdata/parsePackages-interface.txtar index 96bb0fd..576b803 100644 --- a/internal/gno/testdata/parsePackages-interface.txtar +++ b/internal/gno/testdata/parsePackages-interface.txtar @@ -69,6 +69,14 @@ var x interface{ Baz(int) bool } "Name": "Baz", "Signature": "Baz(int) bool", "Kind": "method", + "Fields": [ + { + "Name": "int", + "Signature": "int", + "Kind": "field", + "Type": "int" + } + ], "Type": "bool" } ] diff --git a/internal/gno/testdata/parsePackages-variable.txtar b/internal/gno/testdata/parsePackages-variable.txtar index 96c02e9..b939014 100644 --- a/internal/gno/testdata/parsePackages-variable.txtar +++ b/internal/gno/testdata/parsePackages-variable.txtar @@ -12,7 +12,7 @@ type MyType struct { d int } -func (MyType) F(int) bool { return false } +func (MyType) F(i int) bool { return false } func (o *otherType) f(int) bool { return false } @@ -70,9 +70,17 @@ func Hello() { }, { "Name": "F", - "Signature": "func (MyType) F(int) bool", + "Signature": "func (MyType) F(i int) bool", "Kind": "method", "Recv": "MyType", + "Fields": [ + { + "Name": "i", + "Signature": "i int", + "Kind": "field", + "Type": "int" + } + ], "Type": "bool" } ] @@ -93,6 +101,14 @@ func Hello() { "Signature": "func (o *otherType) f(int) bool", "Kind": "method", "Recv": "otherType", + "Fields": [ + { + "Name": "int", + "Signature": "int", + "Kind": "field", + "Type": "int" + } + ], "Type": "bool" } ]