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:

--- @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<con_color>
--- @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 摘要。