Support ---@return <type>? #desc
The @return tag uses Ty for second field which doesn't support Opt <type>?, this seems to results in the following behaviour:
---Some func
---@param some? string Optional param parsed correctly
---@return string? #This end up as part of `some` param desc
function M.func(some) end
Yields
M.func({some?}) *M.func*
Some func
Parameters: ~
{some?} (string) Optional param parsed correctly
@return string? #This end up as part of `some` param desc
This may not be part of EmmyLua spec but lua_ls specific, but considering ---@param name? <type> works I would expect the same for ---@return <type>? #desc. ---@return string|nil #foo works fine.
IIRC ? is not supported in return right now. I am also not sure if lua_ls supports it or not, or maybe they forget to spec it in their wiki. In any case this is fairly trivial to fix.
IIRC
?is not supported in return right now. I am also not sure if lua_ls supports it or not, or maybe they forget to spec it in their wiki. In any case this is fairly trivial to fix.
You're right that it's not on the lua_ls annotations wiki, but the language server does respect ---@return type?, just adding the ? stops it from bitching about nil returning func. Don't know if it's officially part of the spec or semi-official convenience added. I've been using it for quite a while so it's not anything very recently added. Would be nice if it could be supported, but switching to type|nil isn't a big deal either.
Edit: opened an issue in the lua_ls repo asking for clarification on this.
I can add support for that.