lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

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

Open SReject opened this issue 1 year ago • 1 comments

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

SReject avatar Apr 19 '24 12:04 SReject

A future feature ---@class (partial) A may meet your needs.

CppCXY avatar Apr 22 '24 02:04 CppCXY