-
-
Notifications
You must be signed in to change notification settings - Fork 336
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
Request: Support @field
in both enum and table definitions.
#2960
Comments
Why do you want to write an extra annotation? Isn't it better to just use field = 5? |
I am just trying to make the process of exporting from C a bit easier. An example: It would be convenient to be able to just copy this out into a That said, I can generate Lua too, and maybe it's more appropriate. |
I don't want to run AI in CI, I will just write a program to do it. Thanks for the reply. It's okay to close this issue if you don't like it. :-) |
In LuaLS ---@enum T
T = {
a = 1,
b = 2,
}
--> the same as
---@alias T 1|2 So the type in With that said, there is another feature request to Add ability to define an enum without using a table: #2721, maybe it suits you better for this case and you would like to |
@tomlau10 thanks for the detailed response! However I don't believe either of these notations are sufficient. e.g. ---@enum MyBool
MyBool {
---This is true.
myTrue = 1,
---This is not true.
myFalse = 0
} Where do I define the name and comment for
But it's okay, I think it's fine to define a table. I have actually coded up a generator: |
I mean the type checking behavior of Consider the following: ---@enum MyBool1
MyBool = {
myFalse = 0,
myTrue = 1,
}
---@param a MyBool1
function test1(a) end
test1(MyBool.myFalse) -- valid
test1(1) -- valid
test1(2) -- warn: param-type-mismatch
---
---@alias MyBool2 1|0
---@param a MyBool2
function test2(a) end
test2(MyBool.myFalse) -- valid
test2(1) -- valid
test2(2) -- warn: param-type-mismatch => they have the same type checking behavior, that's what I want to express in my previous reply 😄 Furthermore, ---@alias MyBool3
---| 0 # myFalse, this is not true
---| 1 # myTrue, this is true
---@param a MyBool3
function test3(a) end Then when you hover over the function function test3(a: MyBool3)
a:
| 0 -- myFalse, this is not true
| 1 -- myTrue, this is true |
Wow, that's great @tomlau10. Okay, I think the level of support is reasonable and it's up to me to decide on how I want to handle the annotations on the C side then. Thank you so much for the detailed and quick response! 🙏 |
Request: Allow adding a field type to tables and enum definitions using the
@field
annotation.This is useful for generating meta files from C code where there is no Lua table literal to copy.
See current behaviour below:
@class
✅ Using
@field
✅ Using literal code
✅ Using type annotation
@enum
❌ Using field
Error: The field must be defined after the class.Lua Diagnostics.(doc-field-no-class)
✅ Using literal code
✅ Using type annotation
Untyped table
❌ Using field
Error: The field must be defined after the class.Lua Diagnostics.(doc-field-no-class)
✅ Using literal code
✅ Using type annotation
The text was updated successfully, but these errors were encountered: