LuaLS / LuaLS/lua-language-server
Proposal: Add @constructor Tag for Class Constructors in Lua LSP
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ả
This Lua LSP could benefit from a new @constructor tag, which would be used when defining classes, especially with libraries. Currently, we have to do something like this:
---@class myCls
---@overload fun(a: integer, b: integer): myCls
local myCls = class "myCls"
---@param a integer
---@param b integer
function myCls:__init(a, b)
self.a = a
self.b = b
end
local instance = myCls(10, 20)
print(instance)
As you can see, we need to create an overload for the variable, which makes the typing process quite repetitive. To address this, we could introduce a new @constructor tag that would automatically handle this:
---@class myCls
local myCls = class "myCls" -- No need for an overload anymore.
-- Defining this method as the constructor:
---@constructor
---@param a integer
---@param b integer
function myCls:__init(a, b)
self.a = a
self.b = b
end
local instance = myCls(10, 20) -- Type checking would work correctly and show the constructor parameters.
print(instance)
This approach would make the code cleaner and more intuitive, reducing the need for repetitive annotations and improving the overall developer experience.
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 việc xem xét hành vi hiện có của @class và @overload dựa trên các ví dụ trong issue này; không có tệp, bài kiểm thử hay điểm vào nào được nêu. Công việc được xem là hoàn tất khi việc đánh dấu init bằng @constructor cung cấp các tham số của constructor cho những lệnh gọi như myCls(10, 20), mà không yêu cầu một overload riêng.
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
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- 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
- 25/100