LuaLS / LuaLS/lua-language-server

Difference in behavior between table literal, dictionary, and class in terms of completion

Aperta
#2,217 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

enhancement
Lingua principale
Lua
Stelle
4.4k
Fork
442
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

L’issue non indica alcun file sorgente o test; inizia tracciando, usando i tre esempi Lua, la gestione della completion da parte del language server per i campi di classe, gli alias di dizionario e i letterali di tabella. Il lavoro è completato quando espressioni indicizzate e con notazione a punti equivalenti forniscono il tipo previsto e i suggerimenti di completion previsti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
lua
Ambito
developer-experience
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.