LuaLS / LuaLS/lua-language-server
When using alias values as its keys, Dictionary types don't give completion when defining an instance of that dictionary
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?
Linux
What is the issue affecting?
Completion
Expected Behaviour
When trying to define a table annotated with ---@type {[an_alias]: a_type}, beginning to type a key in the table brings up an_alias's values for automatic completion.
Actual Behaviour
When trying to define a table annotated with ---@type {[an_alias]: a_type}, beginning to type a key in the table will not bring up an_alias's values.
Reproduction steps
Enter the following:
---@alias Flavor
---| "sweet"
---| "spicy"
---| "tangy"
---| "juicy"
---| "tough"
---| "gummy"
---@type {[Flavor]: number}
local test = {
}
Try typing "s" into the empty line in the test table, and it should be able to tell that you'd like to type sweet or spicy because those are members of the Flavor alias, but it does not. It recognizes those words as words found elsewhere in the document and will display them in the autocompletion dropdown as such (below other words found elsewhere in the document that also start with "s"), as shown in this screenshot of a larger file:
This might not be the best of examples because there are no other words that start with "s" in the code, but hopefully the issue is still clear. Adding other things (defining variables, using strings, what not) that start with "s" into the example code will give a result like my screenshot.
Additional Notes
I've tried to make this work with the ---@class annotation, and it behaves how I'd expect (the autocompletion dropdown's first results are field names on that class), but it brings up another issue: I'm trying to iterate through an instance of the class, and I don't get the correct return types when using functions like pairs. That makes sense to me - an object is probably not meant to be iterated through, because it likely has fields of different types.
I'm running into this issue because I'm trying to define a dictionary, i.e. a collection of fields that do have the same type. I know all of the names of the fields beforehand, and I define them in an alias. It seems to me that the language server should be able to recognize when I begin typing one of the alias's values in a table that's being defined as a dictionary with that alias as its keys.
Log File
No response
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 hành vi hoàn thành với alias Flavor và bảng ---@type {[Flavor]: number} được hiển thị trong issue. Truy theo điểm vào của tính năng hoàn thành đối với các khóa trong các bảng dictionary có chú thích và so sánh với tính năng hoàn thành trường lớp; được coi là hoàn thành khi các giá trị của alias như sweet và spicy được ưu tiên khi nhập một khóa.
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
- tooling
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 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
- 45/100