LuaLS / LuaLS/lua-language-server

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

オープン
#1,132 コメント 0 件 リアクション 4 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

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.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

{
  "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"

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まずアノテーションの例を読み、その後、提案されている .luarc.json、meta/3rd/$lib/config.lua、モジュールごとのバージョンソースを比較します。issue では実装ファイルやテストが指定されておらず、いくつかの段階案が説明されているため、まずライブラリドキュメントで @since、@deprecated、@removed を公開する範囲について合意します。完了条件には、定義済みのアノテーション構文とバージョンソースの動作を含める必要があります。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
lua
領域
tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。