LuaLS / LuaLS/lua-language-server
feature: @since/@deprecated/@removed annotations for 3rd party libraries
未关闭
还没有人认领这个 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
---@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.updatedfrom my example) - provide diagnostics
- "warning:
lib.deprecatedhas been deprecated in version 2.0 (your version: 2.1)" - "error:
lib.removedwas removed in version 3.0 (your version: 4.7)"
- "warning:
discovering the library version
Here are some ideas I have:
explicitly-configured by the user
.luarc.json
{
"workspace": {
"library.version": {
"OpenResty": "1.2.3",
},
}
}
discoverable from meta/3rd/$lib/config.lua
top-level version declaration
version = function(workspace_dir)
-- do something to determine the version
return require("my_library").meta.version
end
using config actions
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
-- lib.lua
---@version-from-field _VERSION
local lib = {
_VERSION = "1.2.3",
}
return lib
-- main.lua
local lib = require "lib" -- version is 1.2.3
by library author, from annotation
-- lib.lua
---@version 1.2.3
local lib = {}
return lib
-- main.lua
local lib = require "lib" -- version is 1.2.3
by library user
---@version 1.2.3
local lib = require "lib"
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先阅读注解示例,然后比较拟议的 .luarc.json、meta/3rd/$lib/config.lua 和各模块的版本来源。issue 没有指定实现文件或测试,并描述了几个可能的阶段,因此首先要就库文档中公开 @since、@deprecated 和 @removed 的范围达成一致。完成标准应包括已定义的注解语法和版本来源的行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- tooling
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100