LuaLS / LuaLS/lua-language-server

Request: Support `@field` in both enum and table definitions.

Open
#2,960 8 comments 0 reactions 0 assignees View on GitHub

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
---@class Foo
---@field myField 5
Foo = {}
✅ Using literal code
---@class Foo
Foo = {
  myField = 5,
}
✅ Using type annotation
---@class Foo
Foo = {
  ---@type 5
  myField = nil,
}

@enum

❌ Using field
---@enum Foo
---@field myField 5
Foo = {}

Error: The field must be defined after the class.Lua Diagnostics.(doc-field-no-class)

✅ Using literal code
---@enum Foo
Foo = {
  myField = 5,
}
✅ Using type annotation
---@enum Foo
Foo = {
  ---@type 5
  myField = nil,
}

Untyped table

❌ Using field
---@field myField 5
Foo = {}

Error: The field must be defined after the class.Lua Diagnostics.(doc-field-no-class)

✅ Using literal code
Foo = {
  myField = 5,
}
✅ Using type annotation
Foo = {
  ---@type 5
  myField = nil,
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.