lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

[Feature request] Annotation for referring to superclass

Open Sheepolution opened this issue 1 year ago • 0 comments

I'm trying to add annotations to classic, but encounter a few problems when doing so.

For example, the super field refers to the superclass. If I were to annotate super like this

---@class Object
---@field protected super Object

then subclasses will have a super field, but it will always refer to Object, instead of their superclass. The best solution I can come up with the current implementation is to set the super field each time a class is created.

---@class Animal : Object
---@field super Object
local Animal = Object:extend()

---@class Bird : Animal
---@field super Animal
local Bird = Object:extend()

This is a repetition of steps, which tells me DRY. I suggest something like a super annotation, which always refers to the superclass relative to which class it is being used.

---@class Object
---@field protected super super

---@class Animal : Object
local Animal = Object:extend()
-- Animal.super refers to Object

---@class Bird: Object
local Bird = Animal:extend()
-- Bird.super refers to Animal

Sheepolution avatar Jan 21 '24 01:01 Sheepolution