LuaLS / LuaLS/lua-language-server
Defining table fields of a class across multiple files breaks auto-complete
Nessuno ha ancora preso questa issue.
- Lingua principale
- Lua
- Stelle
- 4.4k
- Fork
- 442
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
### 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_
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci il problema usando Class_Main.lua, Class_Extensions.lua e UserCode.lua del report o dell’esempio allegato nell’estensione Visual Studio Code. Inizia tracciando il completamento per MyClass.SomeTable tra i file e confrontalo con il comportamento di hover e vai alla definizione, che funzionano già. Il lavoro è terminato quando il completamento elenca sia A che B quando la tabella viene utilizzata da un altro file.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- lua
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100