Lua Tools is a set of command-line utilities designed to assist developers working with Lua by:
- lua_commenter: Automatically adding comments and Lua LSP annotations to functions and classes in Lua source files without altering code structure or formatting.
- lua_header: Extracting and generating Lua header files containing public function signatures and relevant documentation.
These tools enhance code maintainability and provide better integration with Lua Language Server features.
To build the project, run:
cargo build --release
This will generate two executables:
target/release/lua_commenter
target/release/lua_header
To make them globally accessible, copy them to a directory in your system's $PATH
.
cp target/release/lua_commenter target/release/lua_header /usr/local/bin/
lua_commenter [options] <input-files>
-o, --output <pattern>
→ Define output filename pattern (e.g.,annotated_{}
forfile.lua
→annotated_file.lua
).-w, --overwrite
→ Modify files in-place instead of creating new ones.-r, --recursive
→ Recursively process all.lua
files in the specified directory.
lua_commenter -o annotated_{} examples/example.lua
This will generate annotated_example.lua
with added comments.
lua_header [options] <input-files>
-r, --recursive
→ Recursively process all.lua
files in the specified directory.
lua_header examples/example.lua
This generates example.header.lua
, containing only public function signatures with comments.
- The tool does not alter the structure, formatting, or logic of the Lua code.
- It only adds missing comments and annotations without overwriting existing ones.
- Uses
---@function
,---@param
, and---@return
annotations. - Omits
---@param
if no parameters exist. - Avoids unnecessary
---@return
annotations for functions without a return value.
For more details on Lua LSP annotations, refer to the official documentation: Lua Language Server Annotations
- Support for detecting more complex return types using deeper code analysis.
- Configuration options to allow customization of annotations and output formatting.
- Integration with Lua Language Server for real-time annotation support.
This toolset aims to automate tedious documentation tasks while maintaining code readability and integrity. 🚀