LuaLS / LuaLS/lua-language-server

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

オープン
#2,313 コメント 0 件 リアクション 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?

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

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

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

はじめの一歩

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

調査の方向性

Visual Studio Code extension で、報告または添付された例にある Class_Main.lua、Class_Extensions.lua、UserCode.lua を使って問題を再現します。まず、ファイル間で MyClass.SomeTable の補完を追跡し、すでに動作しているホバーおよび定義へ移動の動作と比較します。別のファイルからテーブルにアクセスしたときに、補完で A と B の両方が一覧表示されれば完了です。

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

評価

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

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

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