LuaLS / LuaLS/lua-language-server

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

Aberta
#2,313 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Linguagem predominante
Lua
Estrelas
4.4k
Forks
442
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Reproduza o problema usando Class_Main.lua, Class_Extensions.lua e UserCode.lua do relatório ou do exemplo anexado na extensão do Visual Studio Code. Comece rastreando a conclusão de MyClass.SomeTable entre os arquivos e compare-a com o comportamento de hover e ir para a definição, que já funcionam. A tarefa estará concluída quando a conclusão listar A e B ao acessar a tabela a partir de outro arquivo.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
lua
Domínio
devtools
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
35/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.