LuaLS / LuaLS/lua-language-server

---@template<class: T1, class: T2>

Open
#1,732 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement feat/generic
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?

Other

### Expected Behaviour

![image](https://user-images.githubusercontent.com/57856647/204527215-459458c4-af73-4349-9f4f-5f4352ff23aa.png)
![image](https://user-images.githubusercontent.com/57856647/204527274-b0adbbbe-ab1d-4c70-8f47-dbbf15df6b05.png)
![image](https://user-images.githubusercontent.com/57856647/204527334-0fb770ea-5935-4f39-8941-b585c1463f42.png)

### Actual Behaviour

![image](https://user-images.githubusercontent.com/57856647/204526986-a64c511a-6b06-4a1c-a5bf-4e6c763098cd.png)
![image](https://user-images.githubusercontent.com/57856647/204527009-4a827cd7-cae3-4a4e-9297-9f34f98117b2.png)
![image](https://user-images.githubusercontent.com/57856647/204527061-141045ca-65fb-4122-90a4-19d86761a0cc.png)

### Reproduction steps

Is it possible to implement this annotation method?

```lua
---@diagnostic disable: missing-return

function CreateFramePool(...) end
function CreateFrame(...) end

---@template
---@class ObjectPoolMixin
---@field creationFunc fun(self: self)
---@field resetterFunc fun(self: self, object: T)
---@field activeObjects T[]
---@field inactiveObjects T[]
---@field hashinactiveObjects T[]
---@field numActiveObjects integer
ObjectPoolMixin = {};

---@template
---@param creationFunc fun(self: T)
---@param resetterFunc fun(self: self, object: T)
function ObjectPoolMixin:OnLoad(creationFunc, resetterFunc) end

---@template
---@return T object
---@return boolean isNew
function ObjectPoolMixin:Acquire() end

---@template
---@class FramePoolMixin: ObjectPoolMixin
---@field parent T1
FramePoolMixin = {};

---@class Button1
---@field a table
---@field b integer
local Button1 = {};

---@class Button2
---@field c string
---@field d number
local Button2 = {};

---@class Frame1
local frame1 = CreateFrame("Frame");

---@class Frame2
local frame2 = CreateFrame("Frame");

---@class Frame1Pool: FramePoolMixin
frame1.pool = CreateFramePool("Button", frame1);

---@class Frame2Pool: FramePoolMixin
frame2.pool = CreateFramePool("Button", frame2);

local parent1 = frame1.pool.parent; -- Should be defined as Frame1
local parent2 = frame2.pool.parent; -- Should be defined as Frame2

local activeObjects1 = frame1.pool.activeObjects; -- Should be defined as Button1[]
local activeObjects2 = frame2.pool.activeObjects; -- Should be defined as Button2[]

local button1 = activeObjects1[1]; -- Should be defined as Button1 or nil
local button2 = activeObjects2[1]; -- Should be defined as Button2 or nil

```

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

Start with the Lua reproduction in the issue, focusing on the @template and @class inheritance annotations and the expected types for parent and activeObjects. Trace how the language server currently interprets these annotations, then verify that the example preserves both template parameters and resolves the shown fields as Frame1/Frame2 and Button1[]/Button2[].

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.