Implement constructors
This commit is contained in:
@@ -1,7 +1,11 @@
|
|||||||
---@diagnostic disable: missing-return
|
---@diagnostic disable: missing-return
|
||||||
{{range .Fields -}}
|
{{range .Fields -}}
|
||||||
---@field {{.Name}} {{.Type}} {{.Comment}}
|
---@field {{.Name}} {{.Type}} {{.Comment}}
|
||||||
{{end}}
|
{{end -}}
|
||||||
|
{{range .Constructors -}}
|
||||||
|
---@overload fun({{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param.Name}}: {{$param.Type}}{{end}}): {{$.ClassName}}
|
||||||
|
{{end -}}
|
||||||
|
---@class {{.ClassName}}
|
||||||
{{.ClassName}} = {
|
{{.ClassName}} = {
|
||||||
{{$n := len .Methods -}}
|
{{$n := len .Methods -}}
|
||||||
{{$methods := len .Methods -}}
|
{{$methods := len .Methods -}}
|
||||||
@@ -19,5 +23,6 @@
|
|||||||
{{end}}{{end}}
|
{{end}}{{end}}
|
||||||
}
|
}
|
||||||
|
|
||||||
---@type ({{$.ClassName}} | fun(): {{$.ClassName}})
|
---@type {{$.ClassName}}
|
||||||
|
-- Define class globally so it's "available" to other files
|
||||||
{{$.ClassName}} = nil
|
{{$.ClassName}} = nil
|
11
main.go
11
main.go
@@ -77,6 +77,17 @@ func main() {
|
|||||||
Comment: "test method",
|
Comment: "test method",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Constructors: []Constructor{
|
||||||
|
{
|
||||||
|
Params: []Param{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Params: []Param{
|
||||||
|
{Name: "a", Type: "int", Comment: "test param 1"},
|
||||||
|
{Name: "b", Type: "string", Comment: "test param 2"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
ltemplate, err := template.New("class").Funcs(fns).Parse(templatestr)
|
ltemplate, err := template.New("class").Funcs(fns).Parse(templatestr)
|
||||||
|
Reference in New Issue
Block a user