fixup! feat: implement record's metamethod for Constructor
ci/woodpecker/pr/docker-build Pipeline was successful Details
ci/woodpecker/pr/lint Pipeline was successful Details
ci/woodpecker/pr/test Pipeline was successful Details
ci/woodpecker/pr/build-and-run Pipeline failed Details

This commit is contained in:
Aire-One 2023-12-21 00:40:11 +01:00
parent c3847b43c6
commit ac0456e704
3 changed files with 29 additions and 8 deletions

View File

@ -181,7 +181,13 @@ describe("Teal type definition Printer", function()
token = "enum", token = "enum",
}, },
{ {
parameters = {}, parameters = {
{
types = { "Timer" },
name = "self",
token = "variable",
},
},
return_types = {}, return_types = {},
name = "timer", name = "timer",
metamethod = "__call", metamethod = "__call",
@ -200,7 +206,7 @@ describe("Teal type definition Printer", function()
local record Timer local record Timer
enum Signal enum Signal
end end
metamethod __call: function() metamethod __call: function(self: Timer)
end end
return Timer return Timer

View File

@ -905,7 +905,13 @@ describe("Scrap documentation", function()
token = "enum", token = "enum",
}, },
{ {
parameters = {}, parameters = {
{
types = { "Timer" },
name = "self",
token = "variable",
},
},
return_types = {}, return_types = {},
name = "timer", name = "timer",
metamethod = "__call", metamethod = "__call",

View File

@ -221,6 +221,17 @@ local function extract_section_signal(dl: string): { string }
return scraper_utils.scrape(dl, selector, extract_node_text) return scraper_utils.scrape(dl, selector, extract_node_text)
end 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 local enum Section
"Constructors" "Constructors"
"Static module functions" "Static module functions"
@ -238,8 +249,8 @@ local section_scrapers <total>: { Section : function(html: string, record_name:
local constructors <const> = extract_section_functions(html) local constructors <const> = extract_section_functions(html)
for _, constructor in ipairs(constructors) do for _, constructor in ipairs(constructors) do
if constructor.token == "function" and constructor.name == utils.lowercase(record_name) then if constructor.token == "function" and constructor.name == utils.lowercase(record_name) then
constructor.token = "metamethod" add_self_parameter(constructor, record_name)
constructor.metamethod = "__call" transform_to_call_metamethod(constructor)
end end
end end
return constructors, {}, {} return constructors, {}, {}
@ -256,9 +267,7 @@ local section_scrapers <total>: { Section : function(html: string, record_name:
local methods <const> = extract_section_functions(html) local methods <const> = extract_section_functions(html)
for _, method in ipairs(methods) do for _, method in ipairs(methods) do
if method.token == "function" then if method.token == "function" then
local self_parameter = ast.create_node("variable", "self") add_self_parameter(method, record_name)
self_parameter.types = { record_name }
table.insert(method.parameters, 1, self_parameter)
end end
end end
return methods, {}, {} return methods, {}, {}