You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LuaCATS Annotations supports a ---@module syntax. I believe that if this annotation is defined, a valid function namespace should have this module included in the generated output.
For example:
Given an input file like
---@module'my_module'localM= {}
--- Do something.---@paramvaluestring Some text.---@returnnumber? # A value.functionM.to_number(value)
returntonumber(value)
endreturnM
Currently the output is:
==============================================================================------------------------------------------------------------------------------'my_module'------------------------------------------------------------------------------*M.to_number()*
`M.to_number`({value})
Do something.
Parameters ~
{value} `(string)` Some text.
Return ~
`(number)` A value.
vim:tw=78:ts=8:noet:ft=help:norl:
I think it would be better if the output instead would be
==============================================================================------------------------------------------------------------------------------'my_module'------------------------------------------------------------------------------*my_module.to_number()*
`to_number`({value})
Do something.
Parameters ~
{value} `(string)` Some text.
Return ~
`(number)` A value.
vim:tw=78:ts=8:noet:ft=help:norl:
(Note the incorrect 'my_module' at the top. That's a separate bug that isn't related to this feature request)
Extra Considersations
Multiple Namespaces
It's possible to have multiple namespaces in Lua. The documentation generation should take care not to confuse them. For example
---@module'my_module'localM= {}
localH= {}
--- Do something.---@paramvaluestring Some text.---@returnnumber? # A value.functionM.to_number(value)
returnH.to_number2(value)
end--- Do something.---@paramvaluestring Some text.---@returnnumber? # A value.functionH.to_number2(value)
returntonumber(value)
endreturnM
Would generate
==============================================================================------------------------------------------------------------------------------'my_module'------------------------------------------------------------------------------*my_module.to_number()*
`to_number`({value})
Do something.
Parameters ~
{value} `(string)` Some text.
Return ~
`(number)` A value.
------------------------------------------------------------------------------*H.to_number2()*
`H.to_number2`({value})
Do something.
Parameters ~
{value} `(string)` Some text.
Return ~
`(number)` A value.
vim:tw=78:ts=8:noet:ft=help:norl:
Because only M is returned.
Non-Standard Returns
Though uncommon, Lua lets you return you return non-tables. e.g. return "arbitrary thing here". I don't think a docstring autogenerator needs to handle a case like that other than to ignore it.
Table-Returns
More common sometimes people will return a module using a table like this:
---@module'my_module'return {
--- Do something.---@paramvaluestring Some text.---@returnnumber? # A value.to_number3=function(value)
returntonumber(value)
end
}
Though that'd be cool to support too, I'd put that syntax in "nice to have" or a future addition.
The text was updated successfully, but these errors were encountered:
ColinKennedy
changed the title
Add support for @module for documentation auto-generation
[mini.doc] Add support for @module for documentation auto-generation
Sep 18, 2024
ColinKennedy
changed the title
[mini.doc] Add support for @module for documentation auto-generation
[mini.doc] Add support for ---@module annotations
Sep 18, 2024
I think having ---@module act as to replace the returned variable makes sense.
Also, as this seems to be a new-ish LuaCATS adoption and not EmmyLua-style (which 'mini.doc' is based on, yet doesn't claim to have full compatibility), I think it is reasonable to be tracked in a #666. So I'll close this and move/mention the suggestion there.
Contributing guidelines
Module(s)
mini.doc
Description
LuaCATS Annotations supports a ---@module syntax. I believe that if this annotation is defined, a valid function namespace should have this module included in the generated output.
For example:
Given an input file like
Currently the output is:
I think it would be better if the output instead would be
(Note the incorrect
'my_module'
at the top. That's a separate bug that isn't related to this feature request)Extra Considersations
Multiple Namespaces
It's possible to have multiple namespaces in Lua. The documentation generation should take care not to confuse them. For example
Would generate
Because only
M
is returned.Non-Standard Returns
Though uncommon, Lua lets you return you return non-tables. e.g.
return "arbitrary thing here"
. I don't think a docstring autogenerator needs to handle a case like that other than to ignore it.Table-Returns
More common sometimes people will return a module using a table like this:
Though that'd be cool to support too, I'd put that syntax in "nice to have" or a future addition.
The text was updated successfully, but these errors were encountered: