From 386b0f33ff66128ffc3c896bb8b12368af48aa49 Mon Sep 17 00:00:00 2001
From: Aire-One <aireone@aireone.xyz>
Date: Sat, 10 Dec 2022 00:43:01 +0100
Subject: [PATCH 1/2] feat(generator): render static functions

---
 src/awesomewm.d.tl/generator/teal_type_definitions.tl | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/awesomewm.d.tl/generator/teal_type_definitions.tl b/src/awesomewm.d.tl/generator/teal_type_definitions.tl
index d9f58c5..1697d0b 100644
--- a/src/awesomewm.d.tl/generator/teal_type_definitions.tl
+++ b/src/awesomewm.d.tl/generator/teal_type_definitions.tl
@@ -26,7 +26,12 @@ $(snippets.indent(snippets.render_record_properties(module.properties)))
 # if #module.constructors ~= 0 then
    -- Constructors
 $(snippets.indent(snippets.render_record_functions(module.constructors)))
+
 # end -- /constructors
+# if #module.static_functions ~= 0 then
+   -- Static functions
+$(snippets.indent(snippets.render_record_functions(module.static_functions)))
+# end -- /static_functions
 end
 
 return $(module.record_name)
-- 
2.40.1


From 6a9f161594422ee38df0c67211935374f4a52e3c Mon Sep 17 00:00:00 2001
From: Aire-One <aireone@aireone.xyz>
Date: Sat, 10 Dec 2022 01:37:23 +0100
Subject: [PATCH 2/2] fix(scraper): extract_section_functions coupling

Before this fix, the `extract_section_functions` function had issues
with how the elements were discovered. There are some scenarios where
selected nodes weren't from the same function definition. It causes the
generated teal to mix up the function's parameters.
---
 src/awesomewm.d.tl/scraper/module_doc.tl | 47 ++++++++++++++++--------
 1 file changed, 32 insertions(+), 15 deletions(-)

diff --git a/src/awesomewm.d.tl/scraper/module_doc.tl b/src/awesomewm.d.tl/scraper/module_doc.tl
index 33d14ca..81e58dd 100644
--- a/src/awesomewm.d.tl/scraper/module_doc.tl
+++ b/src/awesomewm.d.tl/scraper/module_doc.tl
@@ -115,28 +115,45 @@ end
 
 local function extract_section_functions(dl: string): { Function_Info.Function_Info }
    local query_selectors = {
-      function_name = "dt a",
-      function_parameters = "dd table",
-      function_return_type = "dd ol",
+      header = "dt",
+      name = "a",
+      body = "dd",
+      parameters = "table",
+      return_types = "ol",
    }
 
    return scraper_utils.scrape_tuples(
       dl,
-      { query_selectors.function_name, query_selectors.function_parameters, query_selectors.function_return_type },
+      { query_selectors.header, query_selectors.body },
       function(nodes: { string : scan.HTMLNode | nil }): Function_Info.Function_Info
-         local function_info = Function_Info()
-
-         function_info.name =
-            extract_item_name(nodes[query_selectors.function_name])
-         function_info.parameters =
-            List(extract_function_parameters(nodes[query_selectors.function_parameters]))
-         function_info.return_types = List(
-            extract_function_return_types(
-               nodes[query_selectors.function_return_type]
+         if not nodes[query_selectors.header] or not nodes[query_selectors.body] then
+            log:warn(
+               logger.message_with_metadata(
+                  "Missing header or body",
+                  { nodes = nodes }
+               )
             )
+            error("Missing header or body")
+         end
+         local header = nodes[query_selectors.header] as scan.HTMLNode
+         local body = nodes[query_selectors.body] as scan.HTMLNode
+         local body_elements = scraper_utils.extract_nodes(
+            body:outer_html(),
+            { query_selectors.parameters, query_selectors.return_types }
          )
-
-         return function_info
+         return {
+            name = scraper_utils.scrape(
+               header:outer_html(),
+               query_selectors.name,
+               extract_item_name
+            )[1],
+            parameters = #body_elements:get(query_selectors.parameters) ~= 0 and
+               List(extract_function_parameters(body_elements:get(query_selectors.parameters)[1])) or
+               (List() as List<Function_Info.Parameter>),
+            return_types = #body_elements:get(query_selectors.return_types) ~= 0 and
+               List(extract_function_return_types(body_elements:get(query_selectors.return_types)[1])) or
+               (List() as List<string>),
+         }
       end
    )
 end
-- 
2.40.1