LuaLS / LuaLS/lua-language-server

Annotations with mixins?

Open
#1,860 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

Hi I'm trying to make annotations that must require the user to have certain fields in a table as a requirement.

For instance, I want a table that needs to have x,y fields, or certain functions.

Here is some pseudo-code that might explain what I mean:
```
---@class Spinnable
---@field spin fun()

---@class Positionable
---@field x number
---@field y number
---@field setPos fun(x: number, y: number)

---@generic T : Spinnable, Positionable
---@param p1 `T`
---@return T
local function doFunction(p1) return p1 end

local entity = { x = 5 } -- A table that is missing the other fields
local check = doFunction(entity) -- I want a warning here saying it doesn't have, `y`, `setPos()`, or `spin()`
```

Is this currently possible to require certain fields in a table?

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 reproducing the annotated pseudo-code from the issue and review how the language server handles class annotations, generics, and table-field checks. Done means a table missing y, setPos, or spin produces a diagnostic when passed to doFunction, while a compatible table is accepted.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.