Open renshengongji opened 1 month ago
@enum
actually works like an @alias
, which it is just a type of union values: https://luals.github.io/wiki/annotations/#enum
T = {
a = 1,
b = 2,
}
--> the same as
---@alias T 1|2
Currently @enum
only support value types (string / number / boolean) but not reference type (table / function).
(I don't know if this is the accurate way to describe them)
And when you use (literal) table as enum values, luals seems only recognize them as a generic table, without knowing its content
=> thus you have no completion inside the function with @param event Event
, because luals only treat Event
as @alias Event table|table
(?)
I think I have found a workaround to attach the class type to it:
---@class Event
---@field functionName string
---@field allowCancel boolean
---@diagnostic disable-next-line: duplicate-doc-alias
---@enum Event
Event = {
RENDER = { functionName = "on_render", allowCancel = false },
MOTION = { functionName = "on_motion", allowCancel = true },
}
---@param event Event
function registerEvent(event)
event. --< will suggest: allowCancel, functionName
end
This works by declaring Event
type as a class as well. 🤔
However I don't know if it would cause any other side effect
Issue Description
I want to try creating an Event enum to use for the registering Event method, but enum doesn't seem to support key table values If it can be completed normally like this but If you define a variable or parameter as an enumeration, lls will not know what value it has What I want is to use extend like class, like --- @ class Event: {functionName: string,...} but enum does not seem to support extend
Additional Notes
No response