LuaLS / LuaLS/lua-language-server

Adding ---@class breaks auto completion

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

Linux

What is the issue affecting?

Completion

Expected Behaviour

I'm running into an issue where adding the ---@class annotation to a local variable seems to break auto completion. It should appear correctly even if the ---@class is affixed to a local variable.

Actual Behaviour

The autocomplete variables and functions are not appearing.

Reproduction steps

Here is a simple example of creating a new player class with the issue.

-- Here is a simple example of creating a new player class with the issue
-- Uncommenting the line below *breaks* the autocompletion for p.new()
-- ---@class err.Player
local Player = {}
Player.__index = Player

local function mixin_xy(o)
    o.x = 0
    o.y = 0

    o.set_position = function(self, x, y)
        self.x = x
        self.y = y
    end

    return o
end

function Player.new()
    local self = {}
    self.happy = true
    self = mixin_xy(self)

    return setmetatable(self, Player)
end

local p = Player.new()
-- `p:set_position(), p.x, p.y, p.happy` no longer showing in auto complete if `---@class err.Player` is uncommented

When ---@class err.Player is uncommented, and above local Player = {}:
Image

When ---@class err.Player is removed or commented:

Image

The above image is the expected behaviour. However, when ---@class err.Player is added above local Player = {} it no longer works.

Additional Notes

No response

Log File

No response

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

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

はじめの一歩

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

調査の方向性

報告書の Lua の例を使用して Visual Studio Code 拡張機能で問題を再現し、---@class err.Player アノテーションがある場合とない場合で補完を比較します。クラスアノテーションの補完処理を追跡し、アノテーションが存在する場合に p:set_position()p.xp.yp.happy が表示されることを確認します。

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

評価

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

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

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