LuaLS / LuaLS/lua-language-server

feature: @since/@deprecated/@removed annotations for 3rd party libraries

未關閉
#1,132 0 則留言 4 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

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

描述

I'd love it if we were able to use version markers for 3rd party libraries. OpenResty annotations would benefit from this.

## annotation example

```lua
---@meta
local lib = {}

--- This function was added in lib 1.1.3
---
---@param a string
---@param b string
---@since 1.1.3
function lib.new(a, b) end

--- This function was added in lib 1.1.0 but has been deprecated since 2.0
---
---@param a string
---@param b string
---@since 1.1.0
---@deprecated 2.0
function lib.deprecated(a, b) end

--- This function was added in lib 1.1.0 but has been deprecated since 2.0 and removed in 3.0
---
---@param a string
---@param b string
---@since 1.1.0
---@deprecated 2.0
---@removed 3.0
function lib.removed(a, b) end

--- This function was added in lib 1.0
---
---@param a string
---@param b string
---@since 1.0
function lib.updated(a, b) end

--- ...and the signature was changed in lib 2.0 to add a 3rd param
---
---@param a string
---@param b string
---@param c string
---@since 2.0
function lib.updated(a, b, c) end

return lib
```

Initially, the language server could just add these things to the function's documentation.

Once this feature is in place, the next stage would be to make the language server aware of which version of $library is being used. Then, the language server could use this contextual info:

* provide type hints, docs, etc that are specific for the version being used (see `lib.updated` from my example)
* provide diagnostics
* "warning: `lib.deprecated` has been deprecated in version 2.0 (your version: 2.1)"
* "error: `lib.removed` was removed in version 3.0 (your version: 4.7)"

## discovering the library version

Here are some ideas I have:

### explicitly-configured by the user

`.luarc.json`

```json
{
"workspace": {
"library.version": {
"OpenResty": "1.2.3",
},
}
}
```

### discoverable from meta/3rd/$lib/config.lua

#### top-level `version` declaration

```lua
version = function(workspace_dir)
-- do something to determine the version
return require("my_library").meta.version
end
```

#### using config actions

```lua
configs = {
{
key = 'Lua.workspace.library.version.OpenResty',
action = 'set',
value = (function()
return require("my_library").meta.version
end)(),
},
}
```

### per-module annotation

#### by library author, from table key

```lua
-- lib.lua

---@version-from-field _VERSION
local lib = {
_VERSION = "1.2.3",
}
return lib
````

```lua
-- main.lua

local lib = require "lib" -- version is 1.2.3
```

#### by library author, from annotation

```lua
-- lib.lua

---@version 1.2.3
local lib = {}
return lib
```

```lua
-- main.lua

local lib = require "lib" -- version is 1.2.3
```

#### by library user

```lua
---@version 1.2.3
local lib = require "lib"
```

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

Read the annotation examples first, then compare the proposed .luarc.json, meta/3rd/$lib/config.lua, and per-module version sources. The issue does not name implementation files or tests and describes several possible stages, so first agree on the scope for exposing @since, @deprecated, and @removed in library documentation. Done should include defined annotation syntax and version-source behavior.

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

評估

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

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

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