Skip to content

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

Open

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

Activity

  1. carsakiller commented on Mar 18, 2026

    @carsakiller
    Collaborator

    Additional test case from #3373:

    ---@class Foo
    ---Description of Foo.dostuff
    ---@field dostuff fun(param1: integer)
    foo = {}
    
    function foo.dostuff() end
    
    -- Note that the function above is lacking description, yet there is a definition containing `param1:integer`
    
    ---@type Foo
    local bar = {}
    
    function bar.dostuff() end
    
    -- Now the description is there now that the variable is local
  2. added theissue type on Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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