LuaLS / LuaLS/lua-language-server
Request: Support `@field` in both enum and table definitions.
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
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`
```lua
---@class Foo
---@field myField 5
Foo = {}
```
### ✅ Using literal code
```lua
---@class Foo
Foo = {
myField = 5,
}
```
### ✅ Using type annotation
```lua
---@class Foo
Foo = {
---@type 5
myField = nil,
}
```
## `@enum`
### ❌ Using field
```lua
---@enum Foo
---@field myField 5
Foo = {}
```
`Error: The field must be defined after the class.Lua Diagnostics.(doc-field-no-class)`
### ✅ Using literal code
```lua
---@enum Foo
Foo = {
myField = 5,
}
```
### ✅ Using type annotation
```lua
---@enum Foo
Foo = {
---@type 5
myField = nil,
}
```
## Untyped table
### ❌ Using field
```lua
---@field myField 5
Foo = {}
```
`Error: The field must be defined after the class.Lua Diagnostics.(doc-field-no-class)`
### ✅ Using literal code
```lua
Foo = {
myField = 5,
}
```
### ✅ Using type annotation
```lua
Foo = {
---@type 5
myField = nil,
}
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the @field handling associated with the doc-field-no-class diagnostic; the issue provides Lua examples for @class, @enum, and untyped tables. Done means @field definitions work for enum and table definitions like the examples without that diagnostic, while the existing class behavior remains supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100