LuaLS / LuaLS/lua-language-server
@constraint Annotation for types/aliases
还没有人认领这个 Issue。
- 主要语言
- Lua
- 星标
- 4.4k
- 派生
- 442
- PR 合并指标
- 30 天内没有已合并 PR
描述
I was working with Annotations for documenting my code and wanted to add a warning if the user used a function that didn't fall under a specific pattern (`"0x%x%x%x%x%x%x%x%x"`) and tried finding a workaround. I'm not 100% fluent with .lua and don't have the confidence to PR, so take my idea instead.
My idea for the annotation would be as follows:
```lua
--- @constraint con_color (string.find(T , "^0x%x%x%x%x%x%x%x%x$") or string.find(T , "^%x%x%x%x%x%x$"))
--- @alias color string
--- @param col1 color
--- @param col2 color
local function set_col(col1, col2)
...
end
```
Obviously syntax could use work, but the basic idea would be to add a constraint, and have `T` or whatever variable name be the entry. This way you can give a warning to users about unsupported string or a number being too low/high being used. If there is already something like this please enlighten me as I couldn't find anything
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先检查 language server 现有的 @alias 和 @param 注解处理,因为 issue 没有指定具体的文件或测试。确定提议的 @constraint 语法如何验证别名并生成警告,然后在实现之前定义语法和预期行为;完成意味着已记录的约束对颜色示例有效,并且能够诊断无效值。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100