diff --git a/spec/printer/teal_type_definition_spec.tl b/spec/printer/teal_type_definition_spec.tl index af489be..f00f46b 100644 --- a/spec/printer/teal_type_definition_spec.tl +++ b/spec/printer/teal_type_definition_spec.tl @@ -181,7 +181,13 @@ describe("Teal type definition Printer", function() token = "enum", }, { - parameters = {}, + parameters = { + { + types = { "Timer" }, + name = "self", + token = "variable", + }, + }, return_types = {}, name = "timer", metamethod = "__call", @@ -200,7 +206,7 @@ describe("Teal type definition Printer", function() local record Timer enum Signal end - metamethod __call: function() + metamethod __call: function(self: Timer) end return Timer diff --git a/spec/scraper/module_doc_spec.tl b/spec/scraper/module_doc_spec.tl index 77c27fd..065bf6a 100644 --- a/spec/scraper/module_doc_spec.tl +++ b/spec/scraper/module_doc_spec.tl @@ -905,7 +905,13 @@ describe("Scrap documentation", function() token = "enum", }, { - parameters = {}, + parameters = { + { + types = { "Timer" }, + name = "self", + token = "variable", + }, + }, return_types = {}, name = "timer", metamethod = "__call", diff --git a/src/awesomewmdtl/scraper/module_doc.tl b/src/awesomewmdtl/scraper/module_doc.tl index 1296ca0..b60513e 100644 --- a/src/awesomewmdtl/scraper/module_doc.tl +++ b/src/awesomewmdtl/scraper/module_doc.tl @@ -221,6 +221,17 @@ local function extract_section_signal(dl: string): { string } return scraper_utils.scrape(dl, selector, extract_node_text) end +local function add_self_parameter(function_node: Node, record_name: string) + local self_parameter = ast.create_node("variable", "self") + self_parameter.types = { record_name } + table.insert(function_node.parameters, 1, self_parameter) +end + +local function transform_to_call_metamethod(function_node: Node) + function_node.token = "metamethod" + function_node.metamethod = "__call" +end + local enum Section "Constructors" "Static module functions" @@ -238,8 +249,8 @@ local section_scrapers : { Section : function(html: string, record_name: local constructors = extract_section_functions(html) for _, constructor in ipairs(constructors) do if constructor.token == "function" and constructor.name == utils.lowercase(record_name) then - constructor.token = "metamethod" - constructor.metamethod = "__call" + add_self_parameter(constructor, record_name) + transform_to_call_metamethod(constructor) end end return constructors, {}, {} @@ -256,9 +267,7 @@ local section_scrapers : { Section : function(html: string, record_name: local methods = extract_section_functions(html) for _, method in ipairs(methods) do if method.token == "function" then - local self_parameter = ast.create_node("variable", "self") - self_parameter.types = { record_name } - table.insert(method.parameters, 1, self_parameter) + add_self_parameter(method, record_name) end end return methods, {}, {}