Skip to content

Auto-complete for table keys with @type breaks on non-locals #2332

@PinewoodPip

Description

@PinewoodPip

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

Using ---@type table<KeyType, ValueType> on a table should always keep auto-complete available for keys within the table.

Actual Behaviour

Auto-complete breaks if the table that ---@type was used on is global or within a class.

Reproduction steps

Scenario where auto-complete works:

---@class MyClass
---@field MyThings any

---@type table<string, MyClass>
local SomeTable = {
    SomeKey = {MyField = 1},
    SomeKey2 = {MyField = 1},
}

image

Scenario where auto-complete does not work:

---@class MyClass
---@field MyThings any

---@type table<string, MyClass>
SomeTable = {
    SomeKey = {MyField = 1},
    SomeKey2 = {MyField = 1},
}

No auto-complete will be available for SomeTable there. This also occurs if SomeTable is within a table marked with ---@class.

Additional Notes

No response

Log File

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat/LuaCats AnnotationsRelated to Lua Language Server Annotations (LuaCats)feat/type checkRelated to the type checking feature

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions