LuaLS / LuaLS/lua-language-server
Difference in behavior between table literal, dictionary, and class in terms of completion
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Lua
- Estrellas
- 4.4k
- Forks
- 442
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
El issue no menciona archivos fuente ni pruebas; empieza rastreando, usando los tres ejemplos de Lua, el manejo de completion del language server para campos de clase, alias de diccionario y literales de tabla. Se considera terminado cuando las expresiones indexadas y con notación de punto equivalentes proporcionan el tipo esperado y las sugerencias de completion esperadas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- lua
- Área
- developer-experience
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100