Skip to content

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

@rhys-vdw

Description

@rhys-vdw

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,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions