LuaLS / LuaLS/lua-language-server

Inconsistent Go To Definition Behavior

Offen
#2,839 3 Kommentare 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

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Type Checking

Expected Behaviour

Consider the following code:

---@class A
---@field t table<string, number>
---@field s string

---@class B
---@field a A

---@type B
local b = {
    a = {
        t = { x = 1 },
        s = 'hi',
    }
}

When you ctrl+click (or Go To Definition) on a inside the declaration of variable b, the cursor moves to ---@field a A in the type definition of class B. That's useful behavior. Similarly, when you do the same on s inside the nested a declaration, it goes to --@field s string in class A as expected.

When you click on t however (in t = { x = 1 }, it takes you to the builtin.lua meta file and places the cursor on the definition for tables @class table<K, V>: { [K]: V }. Not only is that behavior not consistent with the above, but it's also completely useless.

Another example (and probably different issue) is if you move the variable declaration to another file, like this:

File 1:

---@class A
---@field t table<string, number>
---@field s string

---@class B
---@field a A

File 2:

---@type B
local b = {
    a = {
        t = { x = 1 },
        s = 'hi',
    }
}

Now going to the definition of t still takes you to builtin.lua, but going to the definition of a, or s does nothing at all. I assume it's because it's treating their "definition" as the same line where they are declared in File 2.

Ideally I would like Go to Definition to do something useful inside table declarations and take me to the type annotation. But if that's not possible it should at least be consistent. In my opinion it should never take you to builtin.lua if there's another more suitable definition.

I think this worked fine in a previous version. I only started to see this behavior in the last few months.

Actual Behaviour

See above.

Reproduction steps

See above.

Additional Notes

No response

Log File

No response

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 den Lua-Snippets im Issue und reproduziere Go To Definition in der Visual Studio Code-Erweiterung unter Windows, wobei du Inline- und dateiübergreifende Deklarationen vergleichst. Verfolge, warum das Feld t zu builtin.lua aufgelöst wird, während a und s anders aufgelöst werden. Erledigt ist die Aufgabe, wenn die Navigation zu Tabellenfeldern konsistent die relevante Typannotation erreicht oder die Definition der Builtin-Tabelle vermeidet, mit Regressionstests für beide Beispiele.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
lua
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

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