So you are using a framework like Busted or OpenResty, but whenever you are using a function from them, you are receiving warnings. This is because the language server has not been told about their existence or how they should be used. Luckily, we can use definition files to supplement this data and receive completion, proper diagnostics, and more.
Addons use definition files to define the various functions and variables of a project. For example, there is already an OpenResty addon that can be found in the LuaCATS organization .
A definition file is simply a Lua file with annotations in it and a @meta
annotation at the top.
Here is a simple example that adds a global class Character
:
---@meta
---@class Character
Character = {}
---@param name string
function Character.hello(name)
print("Hello " .. name .. "!")
end
There are already many definitions available in the form of addons that can be installed using the addon manager in VS Code or found in the LLS-Addons repo or LuaCATS organization .
To use a definition file, provide the path to the file (or parent directory) to workspace.library
.