LuaLS / LuaLS/lua-language-server
Feature Request: Add an option to require type annotations
还没有人认领这个 Issue。
- 主要语言
- Lua
- 星标
- 4.4k
- 派生
- 442
- PR 合并指标
- 30 天内没有已合并 PR
描述
Desire
I would like a way for lua-language-server to apply a "strict" mode to the functions and tables variables of lua files. e.g. if a function takes at least one parameter or has at least one return <foo> statement, it would error if that function doesn't also have a ---@param / ---@return statement to match it.
Issue
There seems to be some arguments that can make lua-language-server more strict, for example these:
.luarc.json
{
"diagnostics": {
"neededFileStatus": {
"incomplete-signature-doc": "Any",
"missing-global-doc": "Any",
"missing-local-export-doc": "Any"
},
"severity": {
"incomplete-signature-doc": "Error",
"missing-global-doc": "Error",
"missing-local-export-doc": "Error"
}
},
}
But they seem to activate only on inlined functions or functions that have incomplete documentation. So if a function has no docs at all, it gets skipped.
Suggestion
A new diagnostic that maybe can be a warning but can be escalated to an error. And it basically says
- If it is a global variable table, it needs a
---@type - If it is a function
- And it has at least one parameter
- Each parameter must define
---@paramwith a name + type
- Each parameter must define
- And it has at least one non-bare-return `return
- Each parameter must define
---@returnwith type
- Each parameter must define
- And it has at least one parameter
- If the type annotation is a table
- Require that the table is "filled out" with concrete types. e.g.
---@type table->---@type table<string, integer>
- Require that the table is "filled out" with concrete types. e.g.
Something along these lines
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 .luarc.json 配置以及现有的 incomplete-signature-doc、missing-global-doc 和 missing-local-export-doc 诊断开始,了解如何启用和升级诊断。定义新诊断针对函数、全局表变量和表注解的范围,然后根据 issue 中的示例验证所请求的警告和错误行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100