LuaLS / LuaLS/lua-language-server

generic param no hint

Open
#2,801 2 comments 0 reactions 0 assignees View on GitHub
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

```lua
---删除物品
---@class pb.S2C_DelItem
---@field itemId integer 物品id

---发送协议到客户端
---@generic T
---@param cmd pb.`T` 命令名
---@param args T
---@return T
function sendToClient(cmd, args)
return nil
end

local ret = sendToClient("S2C_DelItem",{
itemId = 1, -- 无法推断出args为pb.S2C_DelItem类型,输入itemId无字段类型提示
})

ret.itemId -- 返回值能推断出为pb.S2C_DelItem类型,输入itemId有字段类型提示
```

![47d177bc16d5104b26100d38e2e7a69](https://github.com/user-attachments/assets/8f962d45-459b-4fc8-bc70-4792c905da87)
![4373b0763922e91aab1d34326241dd1](https://github.com/user-attachments/assets/95ef19b7-a669-4563-b040-374a5adeac35)

### Actual Behaviour

能正确推断出泛型参数类型并有代码提示

### Reproduction steps

如上代码

### Additional Notes

_No response_

### Log File

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with the generic inference and completion behavior exercised by the sendToClient example in the issue. Reproduce it in the Lua language server with the provided code, then verify that the args table receives pb.S2C_DelItem field hints while the returned value retains its inferred fields.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.