Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wfjt opened this issue Apr 24, 2023 · 3 comments
Open

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

wfjt opened this issue Apr 24, 2023 · 3 comments

Comments

@wfjt
Copy link

wfjt commented Apr 24, 2023

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.

@numToStr
Copy link
Owner

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.

@wfjt
Copy link
Author

wfjt commented Apr 25, 2023

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.

@numToStr
Copy link
Owner

I can add support for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants