lemmy-help icon indicating copy to clipboard operation
lemmy-help copied to clipboard

Support ---@return <type>? #desc

Open wfjt opened this issue 2 years ago • 3 comments

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.

wfjt avatar Apr 24 '23 16:04 wfjt

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.

numToStr avatar Apr 24 '23 16:04 numToStr

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.

wfjt avatar Apr 25 '23 06:04 wfjt

I can add support for that.

numToStr avatar Apr 25 '23 06:04 numToStr