LuaLS / LuaLS/lua-language-server

Defining table fields of a class across multiple files breaks auto-complete

Ouverte
#2,313 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
Lua
Étoiles
4.4k
Forks
442
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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:

---@class MyClass
MyClass = {
    SomeTable = {
        A = "Something",
    },
}

Then another definition of it in another file (an "extension" of the class):


-- 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.

image

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:


---@class MyClass
MyClass = {
    SomeTable = {
        A = "Something",
    },
}

And you try to add keys to SomeTable in another file such as:
Class_Extensions.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:
image

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.

image

Additional Notes

Example folder replicating the issue is attached. It's the same example as the one shown above.
LLS_ClassExtensionBug.zip

Log File

No response

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Reproduisez le problème en utilisant Class_Main.lua, Class_Extensions.lua et UserCode.lua du rapport ou de l’exemple joint dans l’extension Visual Studio Code. Commencez par suivre la complétion de MyClass.SomeTable entre les fichiers, en la comparant au comportement de survol et d’accès à la définition, qui fonctionne déjà. C’est terminé lorsque la complétion liste à la fois A et B lorsque la table est utilisée depuis un autre fichier.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
lua
Domaine
devtools
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.