LuaLS / LuaLS/lua-language-server

Adding ---@class breaks auto completion

Offen
#3,327 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Lua
Sterne
4.4k
Forks
442
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere das Problem in der Visual Studio Code-Erweiterung anhand des Lua-Beispiels im Bericht und vergleiche die Vervollständigung mit und ohne die Annotation ---@class err.Player. Verfolge die Verarbeitung der Vervollständigung für Klassenannotationen und überprüfe, dass p:set_position(), p.x, p.y und p.happy angezeigt werden, wenn die Annotation vorhanden ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
lua
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.