LuaLS / LuaLS/lua-language-server
Defining table fields of a class across multiple files breaks auto-complete
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
### 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:
```lua
---@class MyClass
MyClass = {
SomeTable = {
A = "Something",
},
}
```
Then another definition of it in another file (an "extension" of the class):
```lua
-- 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`:
```lua
---@class MyClass
MyClass = {
SomeTable = {
A = "Something",
},
}
```
And you try to add keys to `SomeTable` in another file such as:
`Class_Extensions.lua`
```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](https://github.com/LuaLS/lua-language-server/files/12551065/LLS_ClassExtensionBug.zip)
### Log File
_No response_
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
Reproduce el problema usando Class_Main.lua, Class_Extensions.lua y UserCode.lua del informe o del ejemplo adjunto en la extensión de Visual Studio Code. Empieza rastreando la finalización de MyClass.SomeTable entre los archivos y compárala con el comportamiento de hover y de ir a la definición, que ya funcionan. La tarea está terminada cuando la finalización muestra tanto A como B al acceder a la tabla desde otro archivo.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- lua
- Área
- devtools
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100