LuaLS / LuaLS/lua-language-server

@constraint Annotation for types/aliases

未关闭
#1,896 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

enhancement feat/LuaCats Annotations
主要语言
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

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先检查 language server 现有的 @alias 和 @param 注解处理,因为 issue 没有指定具体的文件或测试。确定提议的 @constraint 语法如何验证别名并生成警告,然后在实现之前定义语法和预期行为;完成意味着已记录的约束对颜色示例有效,并且能够诊断无效值。

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

评估

技术栈
lua
领域
devtools
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

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