From 422d57e8a281148d5508649026ed110fa67415a5 Mon Sep 17 00:00:00 2001 From: Peter Tripp Date: Sun, 2 Feb 2025 13:56:44 -0500 Subject: [PATCH] docs: Add Lua formatters section (stylua) (#24101) --- docs/src/languages/lua.md | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/docs/src/languages/lua.md b/docs/src/languages/lua.md index 282ee529c44ca17bb77ddf9c1b7290e84a701d8a..eeb61dacebf3c4902f53881387f2152db2baf137 100644 --- a/docs/src/languages/lua.md +++ b/docs/src/languages/lua.md @@ -28,3 +28,44 @@ See [LuaLS Settings Documentation](https://luals.github.io/wiki/settings/) for a ] } ``` + +## Formatting + +Zed can enable auto-formatting of code with formatters like [StyLua](https://github.com/JohnnyMorganz/StyLua). + +1. Install [StyLua](https://github.com/JohnnyMorganz/StyLua): `brew install stylua` or `cargo install stylua --features lua52,lua53,lua54,luau,luajit` (feel free to remove any Lua versions you don't need). +2. Add the following to your `settings.json`: + +```json +{ + "languages": { + "Lua": { + "format_on_save": "on", + "formatter": { + "external": { + "command": "stylua", + "arguments": ["--syntax=Lua54", "-"] + } + } + } + } +} +``` + +You can specify various options to StyLua either on the command line above (like `--syntax=Lua54`) or in a `stylua.toml` in your workspace: + +```toml +syntax = "Lua54" +column_width = 100 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 4 +quote_style = "AutoPreferDouble" +call_parentheses = "Always" +collapse_simple_statement = "All" + +[sort_requires] +enabled = true +``` + +For a complete list of available options, see: [StyLua Options](https://github.com/JohnnyMorganz/StyLua?tab=readme-ov-file#options).