LuaLS / LuaLS/lua-language-server

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

Abierto
#3,272 0 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Lua
Estrellas
4.4k
Forks
442
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza reproduciendo el diagnóstico con pcall(vim.cmd, "redrawtabline") en un búfer de Lua de Neovim; después, rastrea los diagnósticos de LuaLS y la inferencia de tipos para tablas invocables con metamétodos __call. Se considera terminado cuando las tablas invocables se aceptan donde se esperan valores de función sin ocultar errores de tipo genuinos, y la reproducción indicada ya no produce ningún diagnóstico.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
lua
Área
devtools
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
42/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.