fixup! feat: Node.return_types should be a { { string } }
ci/woodpecker/pr/docker-build Pipeline was successful Details
ci/woodpecker/pr/build-and-run Pipeline failed Details
ci/woodpecker/pr/lint Pipeline was successful Details
ci/woodpecker/pr/test Pipeline was successful Details

This commit is contained in:
Aire-One 2023-12-20 23:31:23 +01:00
parent 40610de920
commit d0a898134c
4 changed files with 63 additions and 20 deletions

View File

@ -108,7 +108,7 @@ describe("Teal type definition Printer", function()
token = "variable",
},
},
return_types = { { "boolean" } },
return_types = { { "boolean" }, { "nil", "number" } },
name = "kill",
token = "function",
},
@ -121,7 +121,7 @@ describe("Teal type definition Printer", function()
-- This file was auto-generated.
local record Function_Module
kill: function(pid: integer, sig: integer): boolean
kill: function(pid: integer, sig: integer): boolean, nil | number
end
return Function_Module

View File

@ -833,7 +833,53 @@ describe("Scrap documentation", function()
}
}))
-- TODO : should parse correctly types from
-- <td><span class="types"><span class="type">pattern</span>, <a class="type" href="https://www.lua.org/manual/5.3/manual.html#6.4" target="_blank">string</a> or <span class="type">gradient</span></span></td>
it("should parse function return union types and multiple return values #debug", test(
[[
<h2 class="section-header "><a name="Static_module_functions"></a>Static module functions</h2>
<dl class="function">
<dt>
<a class="copy-link js-copy-link" name="load_image" href="#load_image">🔗</a>
<strong><span class="function_modname">awesome.</span>load_image <span class="function_args"> <b>(</b>name<b>)</b></span></strong>
<span class="proptype">
<span class="summary_type"> -&gt;&nbsp;(gears.surface, nil <i>or</i> string)</span></span>
<span class="baseclass">
</span>
</dt>
<dd>
Load an image from a given path.
<h3>Returns:</h3>
<ol>
<li>
<span class="types"><span class="type">gears.surface</span></span>
A cairo surface as light user datum.
</li>
<li>
<span class="types"><span class="type">nil</span> or <a class="type" href="https://www.lua.org/manual/5.4/manual.html#6.4" target="_blank">string</a></span>
The error message, if any.
</li>
</ol>
</dd>
</dl>
]],
"awesome",
{
children = {
{
children = {},
name = "Signal",
token = "enum",
},
{
parameters = {},
return_types = { { "gears.surface" }, { "nil", "string" } },
name = "load_image",
token = "function",
}
},
name = "Awesome",
module_path = "awesome",
dependencies = {},
global = false,
token = "module",
}))
end)

View File

@ -20,11 +20,12 @@ local function render_function_return_types(types: { { string } }): string
if not types or #types == 0 then
return ""
end
local generated = ": "
for _, t in ipairs(types) do
generated = generated .. render_types(t, ", ")
end
return generated
local positional_return_types = utils.map(types, function (t: { string }): string
return render_types(t, " | ")
end)
return ": " .. table.concat(positional_return_types, ", ")
end
local function dedent(str: string): string

View File

@ -104,19 +104,15 @@ local function extract_function_parameters(table_html: string, function_name: st
end
local function extract_function_return_types(ol_html: string): { { string } }
local raw_types = scraper_utils.scrape(
local positional_return_types = scraper_utils.find(
ol_html,
"span.types .type",
extract_node_text)
"span.types")
local types: { { string } } = {}
for _,raw_t in ipairs(raw_types) do
for _,prt in ipairs(positional_return_types) do
local ts: { string } = {}
for t in stringx.split(raw_t)
:filter(
function(s: string): boolean
return s ~= "or" and s ~= ","
end):iter() do
local union_types = scraper_utils.scrape(prt:outer_html(), ".type", extract_node_text)
for _,t in ipairs(union_types) do
table.insert(ts, t)
end
table.insert(types, ts)
@ -284,7 +280,7 @@ function module.get_doc_from_page(html: string, module_path: string): Node, { No
"dl.function",
})
if #html_nodes:get "h2.section-header" ~= #html_nodes:get "dl.function" then
if #html_nodes:get("h2.section-header") ~= #html_nodes:get("dl.function") then
error "The list aren't the same size!"
end