LuaLS / LuaLS/lua-language-server

Returning module type from require wrapper

Đang mở
#1,245 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

enhancement
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ả

I cannot figure out a way to make a function return the type information of a module.
Basically, we have a wrapper function for require, which takes 2 params, the first being the repository, the second being the module name.
It's a weird legacy thing we have to deal with in our code.
I was just wondering how I can annotate that function to return the module type of the second parameter.
It can basically ignore the first parameter. I've added paths to the library & paths etc... and the typing does work when specifying using normal require, just not the custom wrapper.

essentially the code of the wrapping function (not exact, but like I said, the first param can be ignored):

function custom_require(repo, modname)
    return require(modname)
end

I was hoping it could do something similar to the following annotation, but I have not been able to do so.

---@param repo string
---@param modname string
---@return module<modname>

The only way I've got it to work functionally is to use the plugin feature to replace the text, but this screws up the colouring / highlighting of the entire file.

plugin matcher: "()local([^\n]+)custom_require%([^\n,]+,([^\n%)]+)%)()"
with "---@module " .. mod .. "\nlocal" .. varDec .. "require(" .. mod .. ")". (where varDec is the second group match, and mod is the third, the first being the position)

And the "specials" don't help in this case, as that tries to use the first param, not second.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với wrapper custom_require và plugin matcher hiện có được mô tả trong issue, sau đó lần theo cách các kiểu module và "specials" phân giải các tham số. Hoàn thành khi wrapper suy ra kiểu module được trả về từ đối số thứ hai mà không dựa vào việc thay thế văn bản làm hỏng tính năng tô sáng cú pháp.

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

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.