LuaLS / LuaLS/lua-language-server

Feature Request: Add an option to require type annotations

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

还没有人认领这个 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 ---@param with a name + type
    • And it has at least one non-bare-return `return
      • Each parameter must define ---@return with type
  • 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>

Something along these lines

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 .luarc.json 配置以及现有的 incomplete-signature-doc、missing-global-doc 和 missing-local-export-doc 诊断开始,了解如何启用和升级诊断。定义新诊断针对函数、全局表变量和表注解的范围,然后根据 issue 中的示例验证所请求的警告和错误行为。

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

评估

技术栈
lua
领域
devtools
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
冷清
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

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