LuaLS / LuaLS/lua-language-server

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

オープン
#3,211 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Lua
スター
4.4k
フォーク
442
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

types.luaModuleMixin.lua の例を使って警告を再現し、まず language server の private フィールド診断から始めます。クラス宣言とその実装ファイルがどのように関連付けられているかを追跡します。実装からのアクセスで警告が発生しなくなり、それ以外の場所では private フィールドのチェックが引き続き機能していれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
lua
領域
devtools
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。