LuaLS / LuaLS/lua-language-server
[Feature request] Annotation for referring to superclass
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to add annotations to [classic](https://github.com/rxi/classic/blob/master/classic.lua), 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
```lua
---@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.
```lua
---@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.
```lua
---@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
```
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 reviewing the annotation examples and the classic.lua inheritance model referenced in the issue. Determine where class field annotations are resolved and define how a superclass-relative annotation should behave for Object, Animal, and Bird; the issue names no LuaLS files or tests, so completion criteria need to be established before implementation.
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