LuaLS / LuaLS/lua-language-server
feature request: attach a `reason` parameter to `@nodiscard`
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
> [!NOTE]
> I couldn't find an issue for this. sorry if there's a duplicate.
I propose updating the `@nodiscard` annotation to add a "reason" as to why not discard the value:
```lua
---@nodiscard []
```
this would mirror Rust's `#[must_use = "reason"]` annotation.
### example:
```lua
---Creates a new class that inherits from this one.
---@return Class
---@nodiscard This method returns the new class; it's pointless to immediately discard it.
function Object:extend()
-- ...
end
```
discarding the output would then display the warning:
```md
* [warning][Lua Diagnostics.][discard-returns]
The return values of this function cannot be discarded:
This method returns the new class; it's pointless to immediately discard it.
```
note the colon at the end of "discarded".
if not given a reason, it would fall-back to the usual message, with "discarded" ending with a dot and no further explanation
(yes, I'm aware that reason in the Object:extend example isn't exactly... professional 😅)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file or test is named. Start by locating the @nodiscard annotation parser and the discard-returns diagnostic, then trace how annotation text reaches that warning. Done means a supplied reason is displayed with the requested colon punctuation, while an omitted reason preserves the existing message and period.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100