LuaLS / LuaLS/lua-language-server

Feature Request: Add an option to require type annotations

Open
#3,447 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the .luarc.json configuration and the existing incomplete-signature-doc, missing-global-doc, and missing-local-export-doc diagnostics to understand how diagnostics are enabled and escalated. Define the new diagnostic's scope for functions, global table variables, and table annotations, then validate the requested warning and error behavior against the examples in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.