LuaLS / LuaLS/lua-language-server
When defining global variable using `---@class _G` + `---@field`, no autocompletion in `_G.*` for those injected fields
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?
Completion
Expected Behaviour
The _G class is defined in extension's basic.lua, representing the global vairable. I expected the following should merge the defined fields into the global variable.
---@class _G
---@field player_min integer
---@field player_max integer
print(p--[[should have autocompletion]])
print(_G.p--[[should have autocompletion]])
Actual Behaviour
LuaLs recognized the injected field in the hover preview of _G, however no autocompletion for those fields are provided, unless I write _G._G.*.
---@class _G
---@field player_min integer
---@field player_max integer
print(p--[[no autocompletion]])
print(_G.p--[[no autocompletion]])
print(_G._G.p--[[!!! has autocompletion !!!]])
Reproduction steps
Use the code snippet provided above.
Additional Notes
LuaLS actually recognized the injected fields in the hover preview of _G, just the autocompletion is not working as expected.
Meanwhile the workaround is the use ---@type annotation for global variable. However as discussed here, unless the global variable is of table type, otherwise any default value assigned to it will be misleading as the global variable may not be a const.
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
Tái hiện hành vi hoàn thành mã trong tiện ích mở rộng Visual Studio Code bằng đoạn mã Lua được cung cấp, sau đó kiểm tra định nghĩa basic.lua cho _G và đường dẫn hoàn thành mã. Được xem là hoàn tất khi các trường được khai báo bằng @field trên _G xuất hiện trong cả hoàn thành mã toàn cục và hoàn thành mã _G., mà không yêu cầu _G._G..
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
- 38/100