LuaLS / LuaLS/lua-language-server

False-positive type error: `vim.cmd` callable table flagged as "table cannot match fun(...)"

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

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

主要言語
Lua
スター
4.4k
フォーク
442
PR マージ指標
30日以内にマージされた PR はありません

説明

How are you using the lua-language-server?

NeoVim

Which OS are you using?

Linux

What is the issue affecting?

Diagnostics/Syntax Checking

Expected Behaviour

lua-language-server should recognize callable tables (with a __call metamethod) as valid function values. Passing Neovim’s vim.cmd to pcall should not raise a type error.

Actual Behaviour

lua-language-server reports a false-positive type error when vim.cmd (a callable table in Neovim) is passed to pcall:

Cannot assign table to parameter fun(...):...unknown
Type table cannot match fun(...):...unknown

Reproduction steps
  1. In Neovim, open a Lua buffer (e.g., :new | set ft=lua).

  2. Insert the following code:

    -- Works at runtime, but LuaLS flags the next line:
    pcall(vim.cmd, "redrawtabline")
    -- Diagnostic shown by LuaLS:
    -- Cannot assign `table` to parameter `fun(...):...unknown`
    
  3. Observe the diagnostic from lua-language-server.

  4. Execute the code in Neovim (e.g., :luafile %) to confirm it runs without runtime errors.

Additional Notes
  • vim.cmd is a callable table provided by Neovim (implemented via __call metamethod). Direct calls like vim.cmd("redrawtabline") work at runtime. The false-positive only appears when passing vim.cmd as a function value (e.g., to pcall).

  • Workarounds:

    -- Wrap in a function
    pcall(function() vim.cmd("redrawtabline") end)
    
    -- or use the typed API
    pcall(vim.api.nvim_cmd, { cmd = "redrawtabline" }, {})
    
  • Please treat callable tables as functions for the purpose of type checking / inference.

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

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

はじめの一歩

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

調査の方向性

まず、Neovim の Lua バッファで pcall(vim.cmd, "redrawtabline") を使って診断を再現し、次に __call メタメソッドを持つ呼び出し可能なテーブルについて、LuaLS の診断と型推論を追跡します。呼び出し可能なテーブルが関数値を期待する箇所で受け入れられ、正当な型エラーを隠すことなく、提示された再現で診断が出なくなれば完了です。

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

評価

技術スタック
lua
領域
devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

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

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