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",
},
{
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

View File

@ -905,7 +905,13 @@ describe("Scrap documentation", function()
token = "enum",
},
{
parameters = {},
parameters = {
{
types = { "Timer" },
name = "self",
token = "variable",
},
},
return_types = {},
name = "timer",
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)
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 <total>: { Section : function(html: string, record_name:
local constructors <const> = 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 <total>: { Section : function(html: string, record_name:
local methods <const> = 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, {}, {}