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

Literal values in the type definition lead to empty docs #69

Closed
mfussenegger opened this issue Dec 13, 2022 · 2 comments · Fixed by #70
Closed

Literal values in the type definition lead to empty docs #69

mfussenegger opened this issue Dec 13, 2022 · 2 comments · Fixed by #70

Comments

@mfussenegger
Copy link

lua-language-server supports defining literals/an sum type inline in the type definition. An example: @param x "foo"|"bar"

But this seems to break lemmy-help:

local M = {}

--- Foobar
---@param t? "foo"|"bar"
function M.foo(t)
  print(t)
end

return M

Results in:

❮ lemmy-help -f foo.lua
M.foo()                                                                  *M.foo*


vim:tw=78:ts=8:noet:ft=help:norl:

image

Compared with a regular type definition:

local M = {}

--- Foobar
---@param t? string
function M.foo(t)
  print(t)
end

return M

Which works as expected:

❮ lemmy-help -f foo.lua
M.foo({t?})                                                              *M.foo*
     Foobar

    Parameters: ~
        {t?}  (string)


vim:tw=78:ts=8:noet:ft=help:norl:

The long form also works:

local M = {}

--- Foobar
---@param t? string
---|"foo"
---|"bar"
function M.foo(t)
  print(t)
end

return M
❮ lemmy-help -f foo.lua
M.foo({t?})                                                              *M.foo*
     Foobar

    Parameters: ~
        {t?}  (string)  |"foo"
                        |"bar"


vim:tw=78:ts=8:noet:ft=help:norl:
@numToStr
Copy link
Owner

numToStr commented Dec 14, 2022

Fow now enum variants needs to be wrapped with single quote (') whether it's inline or defined with ----@alias. This is a constraint that I deliberately put in otherwise I have to parse different constructs.

---@param t? '"foo"'|'"bar"'
---@alias T
---| '"foo"' # Foo Variant
---| '"bar"' # Bar Variant

There is also ` which allows identifiers as variant, but currently is not supported. https://github.com/sumneko/lua-language-server/wiki/Annotations#alias

image

image

@mfussenegger
Copy link
Author

mfussenegger commented Dec 14, 2022

Fow now enum variants needs to be wrapped with single quote (') whether it's inline or defined with ----@alias.

Oh that's good to know. Thanks

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

Successfully merging a pull request may close this issue.

2 participants