LuaLS / LuaLS/lua-language-server
Class Inheritance Triggers Typing Issues
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Lua
- Star
- 4.4k
- Fork
- 442
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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, Diagnostics/Syntax Checking
Expected Behaviour
To put it in plain terms, this is for a system of UserControls for a settings-panel system. There is a single Superclass, called "MCT.Option", which houses all of the unified behavior of all the UserControls. Then there are subclasses, for each type of UserControl - checkbox, dropdown, etc.
There's an abstracted method on the UserControl "holders", holder:get_option_by_key("user_control_key') that I have annotated as returning an MCT.Option. In reality, that superclass is never actually returned in practice - it's purely abstracted, and any option is one of the several subclasses.
So when I call:
---@type MCT.Option.Checkbox
local option = holder:get_option_by_key("i_know_this_is_a_checkbox")
I'm expecting to very easily call a conversion from superclass -> subclass.
I have all that (I think) I need to tell the debugger that it's a subclass: initial definition of the subclass is ---@class MCT.Option.Checkbox : MCT.Option, Class to tell it its parents, and it reads from the higher methods and properties completely fine.
But when I call ---@type like that, the debugger doesn't let me simply convert from one to another.
I can of course use ---@cast option MCT.Option.Checkbox after the variable is defined, but that's a bit clunkier in my opinion than having the type defined above the variable, and it ends up requiring me to reference the variable in the annotation, so it takes a bit longer to write up (and I have a lot of these!)
Actual Behaviour

Reproduction steps
- Create a superclass:
---@class MySuperclass
local o = {}
- Create a subclass:
---@class MySubclass : MySuperclass
local o = {}
- Create a function that returns MySuperclass
- Try to direct the type that returns from that function into MySublass
Additional Notes
Thank you for all the hard work you've done over the years - I've been using this extension for a very very long time and it's truly a lifesaver.
Log File
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện các ví dụ về lớp cha và lớp con trong issue thông qua extension của Visual Studio Code trên Windows, tập trung vào chẩn đoán kiểm tra kiểu cho việc gán một kết quả MySuperclass cho MySubclass. Theo dõi hành vi kiểm tra kiểu liên quan đến tính kế thừa lớp và xác nhận rằng khi hoàn tất bản sửa lỗi, phép gán được chấp nhận mà không yêu cầu @cast.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- lua
- Lĩnh vực
- devtools
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100