diff --git a/class.go b/class.go index 43d22a0..e1116da 100644 --- a/class.go +++ b/class.go @@ -128,18 +128,22 @@ func ParseClass(file string) (*Class, error) { if err != nil { return nil, fmt.Errorf("error getting fields: %w", err) } - + res.Methods, err = getMethods(doc) if err != nil { return nil, fmt.Errorf("error getting methods: %w", err) } - spew.Dump(res) + // spew.Dump(res) return &res, nil } -// TODO: Implement parsing comments for parameters // TODO: Implement parsing comments for return values +// Something like "---returns (something) -> comment" +// Where "-> comment" is only shown if there's a comment +// And "---returns" only if there's a return type +// This is NOT a luals annotation because we can not use annotations on @overload +// But just a regular plain Lua comment func getConstructors(doc *goquery.Document) ([]Constructor, error) { res := []Constructor{} @@ -169,6 +173,18 @@ func getConstructors(doc *goquery.Document) ([]Constructor, error) { }) }) + constructorDetails := constructorBlock.Children().Eq(1) + constructorParameterDetails := constructorDetails.Find("span.parameter") + constructorParameterDetails.Each(func(i int, s *goquery.Selection) { + param := strings.TrimSpace(s.Text()) + parameterParent := s.Parent() + parameterDescription := parameterParent.Text() + parameterDescription = strings.ReplaceAll(parameterDescription, fmt.Sprintf("\n%s\n", param), "") + parameterDescription = strings.TrimSpace(parameterDescription) + resConstructor.Params[i].Comment = parameterDescription + }) + + spew.Dump(resConstructor) return append(res, resConstructor), nil } @@ -213,4 +229,4 @@ func getMethods(doc *goquery.Document) ([]Method, error) { }) return res, nil -} \ No newline at end of file +} diff --git a/class.tmpl b/class.tmpl index 6d6704e..0703adf 100644 --- a/class.tmpl +++ b/class.tmpl @@ -21,8 +21,12 @@ } -- Define class globally so it's "available" to other files + ---@type {{$.ClassName}} {{range .Constructors -}} +{{range .Params -}} +{{if ne .Comment ""}}---{{.Name}} ({{.Type}}) -> {{.Comment}}{{end}} +{{end -}} ---@overload fun({{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param.Name}}: {{$param.Type}}{{end}}): {{$.ClassName}} {{end -}} {{$.ClassName}} = nil \ No newline at end of file