LuaLS / LuaLS/lua-language-server

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

Open
#2,332 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feat/LuaCats Annotations feat/type check
Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

### 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` 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:

```lua
---@class MyClass
---@field MyThings any

---@type table
local SomeTable = {
SomeKey = {MyField = 1},
SomeKey2 = {MyField = 1},
}
```
![image](https://github.com/LuaLS/lua-language-server/assets/53646914/478ac04a-d887-458d-99c3-e0ada037c08b)

Scenario where auto-complete does not work:
```lua
---@class MyClass
---@field MyThings any

---@type table
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_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the two table-key completion scenarios in the Visual Studio Code extension, comparing local, global, and class-contained tables annotated with table. Trace the completion handling for these annotations and verify that key completion remains available in each scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.