LuaLS / LuaLS/lua-language-server
Generic attribute constraint doesn't work
Nobody has claimed this yet.
- 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?
Type Checking, Completion
Expected Behaviour
When using the @generic attribute on a method (---@generic T : ClassA) and I have a parameter as type T (---@param item T The item), when I hover over that item parameter I would expect it to list all fields in ClassA
Actual Behaviour
It doesn't list the constrained type's fields. I just see the hover tooltip say: (parameter) item: <T:ClassA>, but none of ClassA's fields are shown
Reproduction steps
Use this code:
---@class ClassA
---@field Name string
---@field Thing string
local ClassA = { Name = "name here", Thing = "thingy"}
---Adds an item
---@generic T: ClassA
---@param item T the Item
function ClassA:AddChild(item)
end
And hover over the item parameter on AddChild, and it won't show any of the fields of ClassA
Additional Notes
No response
Log File
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the ClassA/AddChild example and hovering over the item parameter. Trace the generic constraint handling used by type checking and completion, then verify that the hover result exposes ClassA's Name and Thing fields for T and still reports the constrained type correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100