LuaLS / LuaLS/lua-language-server
Defining table fields of a class across multiple files breaks auto-complete
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?
Completion
Expected Behaviour
If we have a class such as:
---@class MyClass
MyClass = {
SomeTable = {
A = "Something",
},
}
Then another definition of it in another file (an "extension" of the class):
-- This file extends the MyClass class.
---@class MyClass
local MyClass = MyClass
MyClass.SomeTable.B = "Other thing"
Trying to access MyClass.SomeTable should show both A and B as options in auto-complete.
Actual Behaviour
If the keys of a table within a class are defined across multiple files, auto-complete will not work for them all. If you access these keys however, the hover tooltip will be correct and go-to-definition will work.
This is best understood with an example folder. I've attached it below and its code is also shown in the reproduction steps.
Reproduction steps
If you have a class definition in one file such as:
Class_Main.lua:
---@class MyClass
MyClass = {
SomeTable = {
A = "Something",
},
}
And you try to add keys to SomeTable in another file such as:
Class_Extensions.lua
-- This file extends the MyClass class.
---@class MyClass
local MyClass = MyClass
MyClass.SomeTable.B = "Other thing"
Then trying to access Class.SomeTable. in another file will not show B as an option in auto-complete. B will only show in auto-complete in the file were it was added, despite Class there being tagged with @class - which I would expect to add B to the class definition and not just the local usage of it.
UserCode.lua:
As mentioned previously, if you do access B by typing it manually, the hover tooltip will be correct and Ctrl+Click to go to definition will work as expected.
Additional Notes
Example folder replicating the issue is attached. It's the same example as the one shown above.
LLS_ClassExtensionBug.zip
Log File
No response
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere das Problem mithilfe von Class_Main.lua, Class_Extensions.lua und UserCode.lua aus dem Bericht oder dem angehängten Beispiel in der Visual Studio Code extension. Beginne damit, die Vervollständigung für MyClass.SomeTable über die Dateien hinweg nachzuverfolgen, und vergleiche sie mit dem bereits funktionierenden Hover- und Gehe-zu-Definition-Verhalten. Fertig ist die Aufgabe, wenn die Vervollständigung sowohl A als auch B auflistet, wenn die Tabelle aus einer anderen Datei heraus verwendet wird.
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
- 35/100