LuaLS / LuaLS/lua-language-server
Feature for Lua 5.4 to warn about unused __close metamethods.
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
### How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
### Which OS are you using?
MacOS
### What is the issue affecting?
Annotations
### Expected Behaviour
I think it would make sense to be able to somehow annotate that a table with a __close metamethod is meant to be used as a local variable with lua 5.4's attribute. This would be useful for raii-like constructs.
### Actual Behaviour
No warning.
### Reproduction steps
Example:
```lua
local function get_resource()
return
setmetatable({}, {
__close = function ()
print('close resource')
end
})
end
local a = get_resource() -- ok
local b = get_resource() -- not okay, should somehow warn
```
### Additional Notes
_No response_
### Log File
_No response_
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
Start with the Lua 5.4 behavior and the provided get_resource reproduction. Determine how the language server represents annotations and warnings, then define a way to identify resources with __close that are assigned without ; done means the example warns for b while accepting a.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100