LuaLS / LuaLS/lua-language-server

LuaLS processes the wrong LuaDoc for Penlight tablex.filter

未關閉
#3,317 2 則留言 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?

Windows

What is the issue affecting?

Libraries

Expected Behaviour
local tablex = require("pl.tablex")

tablex.filter(
    {},
    function() end -- no linting error
)
Actual Behaviour
local tablex = require("pl.tablex")

tablex.filter(
    {},
    function() end -- Cannot assign `function` to parameter `"()"|"<"|"<="|"=="|">"...(+5)`. (...)
)
Reproduction steps
  1. Setup LuaLS and copy example code into a .lua file
  2. Install Penlight using the Addon Manager
Additional Notes

Here's an extract of the LuaDoc. LuaLS seems to always pick the second definition instead of the first one which has the annotations for using a generic function.

---@generic T, A
---@param t T[]
---@param pred fun(val: T, arg: A): any
---@param arg A
---@return T[]
---@nodiscard
function tablex.filter(t, pred, arg) end

---filter an array's values using a predicate function
---@generic T
---@param t T[] -- a list-like table
---@param pred pl.BoolBinOpString -- a boolean function
---@param arg any -- optional argument to be passed as second argument of the predicate
---@return T[]
---@nodiscard
function tablex.filter(t, pred, arg) end

https://github.com/goldenstein64/pl-definitions/blob/ef73834d7b54b989a4decf9f4598b83b3c9ef621/library/pl/tablex.lua#L545

Log File

I set --loglevel=trace and added the code to an empty file while having tail running on the log but there are no relevant details.

$ tail -f ./file_home_function_git_dragdown-modules.log
[13:59:35.741][debug][#0:script/vm/node.lua:490]: clearNodeCache
[13:59:35.741][trace][#0:script/files.lua:286]: Set text:       untitled:Untitled-1     takes   0.00012299999999987     sec.
[13:59:35.741][trace][#0:script/files.lua:695]: Compile State:  untitled:Untitled-1
[13:59:35.843][debug][#0:script/provider/provider.lua:1120]: textDocument/semanticTokens/range
[13:59:35.857][debug][#0:script/provider/diagnostic.lua:330]: publishDiagnostics        untitled:Untitled-1     2
[13:59:40.272][debug][#0:script/vm/node.lua:490]: clearNodeCache
[13:59:40.273][trace][#0:script/files.lua:286]: Set text:       untitled:Untitled-1     takes   0.00021399999999971     sec.
[13:59:40.373][trace][#0:script/files.lua:695]: Compile State:  untitled:Untitled-1
[13:59:40.374][debug][#0:script/provider/provider.lua:1120]: textDocument/semanticTokens/range
[13:59:40.381][info] [#0:script/provider/diagnostic.lua:171]: clearDiagnostics  untitled:Untitled-1
[13:59:47.118][debug][#0:script/vm/node.lua:490]: clearNodeCache
[13:59:47.118][trace][#0:script/files.lua:286]: Set text:       untitled:Untitled-1     takes   0.00020199999999981     sec.
[13:59:47.219][trace][#0:script/files.lua:695]: Compile State:  untitled:Untitled-1
[13:59:47.220][debug][#0:script/provider/provider.lua:1120]: textDocument/semanticTokens/range
[13:59:47.232][debug][#0:script/provider/diagnostic.lua:330]: publishDiagnostics        untitled:Untitled-1     2

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

在 VS Code 中使用 LuaLS 和 Penlight addon 重現該診斷,然後檢查第 545 行附近的 library/pl/tablex.lua,尤其是兩個 tablex.filter 定義。追蹤 LuaLS 如何解析這些定義,並驗證是否選取了泛型多載,使範例不再回報無效的函式引數。

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

評估

技術堆疊
lua
領域
devtools
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

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

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