LuaLS / LuaLS/lua-language-server

@field private in @meta file triggers warning even when accessed within the same class

Aberta
#3,211 7 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?

Annotations

Expected Behaviour

When defining a class in a ---@meta file with @field private annotations, the Lua language server warns about accessing those private fields even when they are accessed within the implementation of the same class (just in a separate file). This makes private fields effectively unusable if you're organizing types in meta files.

The language server should not warn about access to @field private fields when they are accessed within the implementation of the class they belong to, even if that implementation is in a separate file.

I think this is by design rather than a bug, so maybe this is a feature request?

Actual Behaviour

Even though I'm accessing the private field in the implementation of that class, I see a warning:

Image

Reproduction steps
  1. In types.lua (meta file)
---@meta

---@class (exact) ModuleMixin
---@field private __loaded boolean
---@field Load fun(self)
---@field IsLoaded fun(self): boolean
---@field Init fun(self)
  1. ModuleMixin.lua (implementation)
---@type SmartChat.ModuleMixin
local ModuleMixin = {}

function ModuleMixin:Init()
  self.__loaded = false  -- <-- LuaLS warns that __loaded is private
end
Additional Notes

I use a @meta file to separate type annotations from implementation, which is common in larger projects. This issue makes it difficult to use private meaningfully unless everything is co-located in the same file, which defeats the purpose of a metadata/type declaration file.

Would it be possible to make private refer to "the class definition context" rather than "the file only"?

Thanks!

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 aviso usando os exemplos types.lua e ModuleMixin.lua, começando pelo diagnóstico de campos privados no language server. Rastreie como a declaração da classe e seu arquivo de implementação são associados. O trabalho estará concluído quando os acessos vindos da implementação não gerarem mais avisos, enquanto as verificações de campos privados permanecerem intactas em outros locais.

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

Avaliação

Stack de tecnologia
lua
Domínio
devtools
Tipo de issue
Funcionalidade
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.