Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lua/docgen/renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ local function inline_type(obj, classes)
local cls_descs = {}
for _, field in ipairs(cls.fields) do
if not field.access and not vim.startswith(field.name, "_") then
inline_type(field, classes)
local fdesc, fdefault = get_default(field.desc)
if fdesc then fdesc = fdesc:gsub("\n(- {)", "\n %1") end
local field_ty = render_type(field.type, nil, fdefault)
local field_name = format_field_name(field.name)
table.insert(cls_descs, string.format("- %s %s %s", field_name, field_ty, fdesc))
Expand Down
89 changes: 89 additions & 0 deletions tests/renderer_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,95 @@ foo_bar.fire_employee({emp}) *foo.bar.fire_employee()*
assert_funs(input, expect)
end)

it("inlined class inheriting from inlined class", function()
local input = [[
---@class Animal
---@inlinedoc
---@field species string the species name
---@field legs number number of legs

---@class Dog : Animal
---@inlinedoc
---@field name string the dog's name

--- pets the dog
---@param dog Dog
function M.pet_dog(dog) end
]]

local expect = [[
foo_bar.pet_dog({dog}) *foo.bar.pet_dog()*
pets the dog

Parameters: ~
• {dog} (`table`) A table with the following fields:
• {name} (`string`) the dog's name
• {species} (`string`) the species name
• {legs} (`number`) number of legs
]]
assert_funs(input, expect)
end)

it("inlined class field that is itself an inlined class", function()
local input = [[
---@class Point
---@inlinedoc
---@field x number
---@field y number

---@class Box
---@inlinedoc
---@field origin Point
---@field label string

--- draw it
---@param b Box
function M.draw(b) end
]]

local expect = [[
foo_bar.draw({b}) *foo.bar.draw()*
draw it

Parameters: ~
• {b} (`table`) A table with the following fields:
• {origin} (`table`) A table with the following fields:
• {x} (`number`)
• {y} (`number`)
• {label} (`string`)
]]
assert_funs(input, expect)
end)

it("inlined class with three levels of inlined parents", function()
local input = [[
---@class Base
---@inlinedoc
---@field id number

---@class Middle : Base
---@inlinedoc
---@field label string

---@class Leaf : Middle
---@inlinedoc
---@field active boolean

---@param opts Leaf
function M.do_thing(opts) end
]]

local expect = [[
foo_bar.do_thing({opts}) *foo.bar.do_thing()*
Parameters: ~
• {opts} (`table`) A table with the following fields:
• {active} (`boolean`)
• {label} (`string`)
• {id} (`number`)
]]
assert_funs(input, expect)
end)

it("overloads", function()
local input = [[
---@overload fun(x: string): boolean
Expand Down
Loading