LuaLS / LuaLS/lua-language-server

[Feature Request] @mixin - @class specific syntax to define applied mixins

Open
#2,618 1 comment 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

What

A way to indicate that the members of a @class type are applied to a subject @class outside of the inheritance chain

Technical

@mixin type, ...
Adds the values of type, ... to the subject class' definition. Mixins are applied in the order they are specified; values of the same key are overwrote as each mixin is processed

Example

This:

---@class Mixin1
---@field foo number
---@field bar number

---@class Mixin2
---@field bar string
---@field baz string

---@class Subject
---@field key boolean
---@field foo boolean
---@mixin Mixin1, Mixin2

Would get interpreted as

---@class Subject
---@field key boolean (defined by field; wasn't altered by mixins)
---@field foo number (defined by field, overwrote by mixin1, not overwrite by mixin2)
---@field bar string (defined by mixin1, overwrite by mixin2)
---@field baz string (defined by mixin2)

Use case

I currently have sub-classes that get assigned valves from reusable dictionary tables outside their inheritance chain. The only way to document those modifications is to statically define the fields each time a mixin is applied

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

No files or tests are named. Start by tracing how the language server parses existing @class annotations and inheritance, then determine where ordered @mixin application and field overwriting would fit. Done means the syntax is parsed with the stated precedence rules and covered by tests for multiple mixins and collisions.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.