Parse functions and callbacks from root love table

This commit is contained in:
Emma 2024-08-10 16:37:16 -04:00
parent f5bfbf1c26
commit 0cb16a6456

View File

@ -21,7 +21,9 @@
{} {}
(faccumulate [result {} i 1 arg-count] (faccumulate [result {} i 1 arg-count]
(collect [k v (pairs (. args i)) &into result] (collect [k v (pairs (. args i)) &into result]
(values k v)))))) (if (?. result k)
(values k (merge v (. result k)))
(values k v)))))))
(fn fn-arguments->names [arguments] (fn fn-arguments->names [arguments]
"Given an array of arguments, return all names as an array." "Given an array of arguments, return all names as an array."
@ -55,10 +57,13 @@
(when ?docstring (set lsp-value.metadata.fnl/docstring ?docstring)) (when ?docstring (set lsp-value.metadata.fnl/docstring ?docstring))
lsp-value)) lsp-value))
(fn get-love-functions [love-docs-tbl] ; TODO - This function takes the functions object directly, then it can be used
; for any high-level object.
(fn get-love-functions [docs-tbl]
"Takes the LÖVE-API documentation table and generates a list of the "Takes the LÖVE-API documentation table and generates a list of the
library-level functions suitable for the Fennel LSP." library-level functions suitable for the Fennel LSP."
(collect [_i value (ipairs love-docs-tbl.functions)] (collect [_i value (ipairs docs-tbl)]
(let [{: name : description} value (let [{: name : description} value
?variants (?. value :variants) ?variants (?. value :variants)
first-variant (if ?variants first-variant (if ?variants
@ -76,7 +81,8 @@
love-doc-string (.. "LÖVE is a framework for making " love-doc-string (.. "LÖVE is a framework for making "
"2D games in the Lua programming language.") "2D games in the Lua programming language.")
love-docs (build-lsp-value :love nil love-doc-string) love-docs (build-lsp-value :love nil love-doc-string)
love-functions {:fields (get-love-functions love-docs-tbl)}] love-functions {:fields (get-love-functions love-docs-tbl.functions)}
(stringify-table {:love (merge love-docs love-functions)}))) love-callbacks {:fields (get-love-functions love-docs-tbl.callbacks)}]
(stringify-table {:love (merge love-docs love-functions love-callbacks)})))
{: convert} {: convert}