lua-language-server
lua-language-server copied to clipboard
Infer pcall arguments from the first function parameter
Hi 👋
I was wondering if it would be possible for LuaLS to infer the types of the arguments passed to pcall based on the signature of its first function argument. This would significantly improve developer experience, especially when working with typed Lua (e.g., EmmyLua annotations) or when relying on auto-completion and type checking.
Example:
local function greet(name: string)
print("Hello, " .. name)
end
pcall(greet, "world")
^- here we should see `name: string`
In this case, it would be great if LuaLS could infer that greet expects a string, and therefore type-check or suggest "world" accordingly when passed to pcall.
Currently, the parameters after the first one are not checked or suggested with much context, making it less ergonomic when using pcall (or other similar functions) for safe calls.