LuaLS / LuaLS/lua-language-server

Feature for Lua 5.4 to warn about unused __close metamethods.

Open
#2,027 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.