LuaLS / LuaLS/lua-language-server
False-positive type error: `vim.cmd` callable table flagged as "table cannot match fun(...)"
Nessuno ha ancora preso questa issue.
- Lingua principale
- Lua
- Stelle
- 4.4k
- Fork
- 442
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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
-
In Neovim, open a Lua buffer (e.g.,
:new | set ft=lua). -
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` -
Observe the diagnostic from lua-language-server.
-
Execute the code in Neovim (e.g.,
:luafile %) to confirm it runs without runtime errors.
Additional Notes
-
vim.cmdis a callable table provided by Neovim (implemented via__callmetamethod). Direct calls likevim.cmd("redrawtabline")work at runtime. The false-positive only appears when passingvim.cmdas a function value (e.g., topcall). -
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo la diagnostica con pcall(vim.cmd, "redrawtabline") in un buffer Lua di Neovim, quindi traccia la diagnostica di LuaLS e l’inferenza dei tipi per le tabelle chiamabili con metametodi __call. Il lavoro è completato quando le tabelle chiamabili vengono accettate dove sono attesi valori funzione senza nascondere errori di tipo reali e la riproduzione indicata non produce più alcuna diagnostica.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- lua
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100