LuaLS / LuaLS/lua-language-server

Feature Request: Add an option to require type annotations

Offen
#3,447 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Lua
Sterne
4.4k
Forks
442
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der Konfiguration .luarc.json und den vorhandenen Diagnosen incomplete-signature-doc, missing-global-doc und missing-local-export-doc, um zu verstehen, wie Diagnosen aktiviert und eskaliert werden. Lege den Geltungsbereich der neuen Diagnose für Funktionen, globale Tabellenvariablen und Tabellenannotationen fest und validiere anschließend das angeforderte Warnungs- und Fehlerverhalten anhand der Beispiele im Issue.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
lua
Bereich
devtools
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.