LuaLS / LuaLS/lua-language-server
Issues with event function definition
还没有人认领这个 Issue。
- 主要语言
- Lua
- 星标
- 4.4k
- 派生
- 442
- PR 合并指标
- 30 天内没有已合并 PR
描述
When trying to create an event rpc function I ran into several type issue.
```
---@enum EventAudienceEnum
EventAudienceEnum = {
ALL = "ALL",
ALL_BUT_SELF = "ALL_BUT_SELF",
SELF = "SELF",
SELECT = "SELECT",
SERVER = "SERVER",
OWNER = "OWNER",
}
---@class EventAudienceSelect
---@field [0] EventAudienceEnum.SELECT
---@field peer_ids string | string[]
---@class EventAudienceOwner
---@field [0] EventAudienceEnum.OWNER
---@field unit string
---@alias EventAudience
---| EventAudienceEnum.ALL # comment
---| EventAudienceEnum.ALL_BUT_SELF # comment
---| EventAudienceEnum.SELF # comment
---| EventAudienceEnum.SERVER # comment
---| EventAudienceSelect # comment
---| EventAudienceOwner # comment
--- Send event
---@param audience EventAudience who to send the event to
---@param event string event to call
---@param ... any params to pass to the event
function Events.send_event(audience, event, ...)
end
```
Issue 1: Can't use specific enums as types (https://github.com/LuaLS/lua-language-server/issues/2274)
Issue 2: You do not get the missing field diagnostic on 'dictionary', or 'table-literal' types
Ex:
```
---@param audience { [0]: "SELECT", ["peer_ids"]: string | string[] } who to send event to
---@param event string event to call
---@param ... any params to pass to the event
function Events.send_event(audience, event, ...)
end
Events.send_event({
}, "test", "test")
```
and
```
---@param audience { [0]: "SELECT", peer_ids: string | string[] } who to send event to
---@param event string event to call
---@param ... any params to pass to the event
function Events.send_event(audience, event, ...)
end
Events.send_event({
}, "test", "test")
```
gives no errors
Issue 3: Alias comments only show stuff for strings or numbers
I would have expected the alias comment here to also say
```
| EventAudienceSelect
| EventAudienceOwner
```
Issue 4: There is no missing-param diagnostic for 'number' fields:
```
Events.send_event({peer_ids = {}}, "test", "test")
```
I would have expected an error here:
but none is given
Issue 5: There is no type-checking on 'number' fields of classes, unless you explicitly call out the number. For example there is no error here:
even though there is an error here:
Issue 6: There are issues with the missing field diagnostic and unions. For example I get an error that I need to define peer_ids here:
when I would expect it to work as EventAudienceOwener has no peer_ids. I expect this is related to https://github.com/LuaLS/lua-language-server/issues/2252 (and https://github.com/LuaLS/lua-language-server/issues/2102)
Until unions are properly implemented, it would nice to be able to disable the missing-field-diagnostic at the table level instead of at the usage level. (Something like suggested here: https://github.com/LuaLS/lua-language-server/issues/2220)
Sorry this was a little long, let me know if you want me to seperate this out into seperate issues 👍
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先复现 issue #2279 中的六个类型检查和诊断示例,然后将行为与相关 issue #2274、#2252、#2102 和 #2220 进行比较。完成这项工作需要明确范围,并验证所选 enum、missing-field、alias-comment、numeric-field 和 union case 的行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100