LuaLS / LuaLS/lua-language-server

Feature for Lua 5.4 to warn about unused __close metamethods.

未關閉
#2,027 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
Lua
星號
4.4k
分支
442
PR 合併指標
30 天內沒有已合併 PR

描述

### 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_

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 Lua 5.4 的 行為和提供的 get_resource 重現開始。確定語言伺服器如何表示註解和警告,然後定義一種識別帶有 __close 但在沒有 的情況下被指派的資源的方法;完成標準是範例對 b 發出警告,同時接受 a。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
lua
領域
devtools
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。