LuaLS / LuaLS/lua-language-server

"array-like" table can't be natively annotated as enum

未关闭
#2,435 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Lua
星标
4.4k
派生
442
PR 合并指标
30 天内没有已合并 PR

描述

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Linux

What is the issue affecting?

Annotations, Hover

Expected Behaviour

On hover over action param in my function I'd like to get annotation consistent with already existing annotation that i get if i hover over all in actions.all :

(field) actions.all: {
    [10]: string = "supportAttack",
    [11]: string = "supportDefence",
    [12]: string = "supportBoth",
    [13]: string = "supportAttackPike",
    [14]: string = "supportDefencePike",
    [15]: string = "stanceShieldwall",
    [16]: string = "stanceLastman",
    [17]: string = "stanceBarrage",
    [18]: string = "encamp",
    [19]: string = "uncamp",
    [1]: string = "retreat",
    [20]: string = "destroyCamp",
    [21]: string = "buildFort",
    [22]: string = "demountFort",
    [23]: string = "destroyFort",
    [24]: string = "rest",
    [25]: string = "respire",
    [2]: string = "move",
    [3]: string = "swap",
    [4]: string = "forcedMove",
    [5]: string = "melee",
    [6]: string = "shoot",
    [7]: string = "shoot2",
    [8]: string = "breakthrough",
    [9]: string = "enclosing",
}

Essentially i'd like enum for this array to give the same behavioir as alias like this

---@alias Action
---| '"retreat"'
---| '"move"
---| '"swap"' 
---| '"forcedMove"'
---| '"melee"'
---| '"shoot"'
---| '"shoot2"'
---| '"breakthrough"
---| '"enclosing"'
---| '"supportAttack"'
---| '"supportDefence"'
---| '"supportBoth"'
---| '"supportAttackPike"'
---| '"supportDefencePike"'
---| '"stanceShieldwall"'
---| '"stanceLastman"'
---| '"stanceBarrage"'
---| '"encamp"'
---| '"uncamp"'
---| '"destroyCamp"'
---| '"buildFort"'
---| '"demountFort"'
---| '"destroyFort"'
---| '"rest"'
---| '"respire"'
Actual Behaviour

On hover over action param in my function I get this annotation:

(parameter) action: Action
{
}
Reproduction steps

Consider this minimal code snippet:

local actions = {}

---@enum Action
actions.all = {
  "retreat",
  "move",
  "swap",
  "forcedMove",
  "melee",
  "shoot",
  "shoot2",
  "breakthrough",
  "enclosing",
  "supportAttack",
  "supportDefence",
  "supportBoth",
  "supportAttackPike",
  "supportDefencePike",
  "stanceShieldwall",
  "stanceLastman",
  "stanceBarrage",
  "encamp",
  "uncamp",
  "destroyCamp",
  "buildFort",
  "demountFort",
  "destroyFort",
  "rest",
  "respire",
}

actions.isStance = {stanceShieldwall = true, stanceLastman = true, stanceBarrage = true}

--- @param action Action
--- @return boolean
function actions.IsStance(action)
  return actions.isStance[action]
end
Additional Notes

No response

Log File

No response

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 issue 中的最小 Lua 复现开始,跟踪 actions.all 上的 @enum 注解和 Action 参数是如何表示为悬停信息的。将这条路径与现有的别名行为进行比较。当悬停在 Action 参数上时,能够与悬停 actions.all 的结果一致地展示枚举的字符串成员,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
lua
领域
devtools
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。