LuaLS / LuaLS/lua-language-server
Question mark optional syntax not supported in fun() declarations
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
### Expected Behaviour
Optional value to actually be optional
### Actual Behaviour
It's not optional.

This code block should show as Human? and throw warnings for not checking nil. If I manually annotate with `---@param man Human?` this works as expected.
The class in question:
```lua
---@class Command
---@field info string What the command does.
---@field usage string? How to use the command.
---@field alias string[]? Aliases of the command.
---@field canCall (fun(player: Player): boolean)? Function which checks whether a player can call this command.
---@field call fun(player: Player, human: Human?, args: string[]) Calls the command.
---@field autoComplete fun(args: string[])? Function which manipulates arguments when pressing tab in the terminal.
---@field cooldownTime number? How many seconds a player has to wait before using the command again.
```
I have also tried with human?: Human and human?: Human? but neither way works.
### Reproduction steps
1. Create class with a field with a short form function declaration with an optional value parameter
2. Attempt to create object of class with that field,
3. Parameter correctly types, except as not optional.
### Additional Notes
_No response_
### 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 ví dụ về trường của class trong Visual Studio Code extension, tập trung vào khai báo hàm dạng rút gọn với một tham số Human nullable. So sánh với trường hợp được chú thích thủ công `---@param man Human?`; hoàn tất khi tham số được suy luận là tùy chọn và các cảnh báo kiểm tra nil xuất hiện như mô tả.
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, vscode
- Lĩnh vực
- devtools
- 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
- 35/100