LuaLS / LuaLS/lua-language-server
Difference in behavior between table literal, dictionary, and class in terms of completion
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Lua
- Sterne
- 4.4k
- Forks
- 442
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Maybe more of a feature request than a bug, but I noticed some interesting differences between classes, dictionaries, and table literals in terms of completions.
Using this code as a base:
---@class TestClass
---@field test_group TestGroup
---@class TestGroup
---@field test_field string
---@alias TestTableDictionary {["test_group"]: {["test_field"]: string}}
---@alias TestTableLiteral {test_group: {test_field: string}}
---@type TestClass
local test_class
local test_group = "test_group"
local test1 = test_class["test_group"].test_field
---@type TestTableDictionary
local test_table_dictionary
local test_group = "test_group"
local test2 = test_table_dictionary[test_group].test_field
---@type TestTableLiteral
local test_table_literal
local test_group = "test_group"
local test3 = test_table_literal[test_group].test_field
I would expect the completion for test1, test2, and test3 to be equivalent. However there are some interesting differences.
For test 1 if we do this local test1 = test_class[test_group].test_field the type of test1 is unknown and there is no completion suggestions for test_class[test_group]. Both test_class["test_group"].test_field and test_class.test_group.test_field work correctly.
For test 2 test_table_dictionary[test_group].test_field works correctly. test_table_dictionary.test_group.test_field gives the right value but does not show any completion suggestions like the classes do.
For test 3 the table literal is the best of all worlds. You can do test_table_literal[test_group].test_field as well as get completions on test_table_literal.test_group.test_field.
As I am using classes in a lot of places and they are useful as they can be spread across multiple lines and the fields can have longer descriptions it would be awesome to see the ability to do something like test_class[test_group].test_field for classes
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
Das Issue nennt keine Quelldateien oder Tests; beginne damit, anhand der drei Lua-Beispiele die Completion-Verarbeitung des Language Servers für Klassenfelder, Wörterbuch-Aliase und Tabellenliterale nachzuverfolgen. Als abgeschlossen gilt die Arbeit, wenn äquivalente indizierte und punktierte Ausdrücke den erwarteten Typ und die erwarteten Vervollständigungsvorschläge liefern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- lua
- Bereich
- developer-experience
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100