lua.md

 1# Lua
 2
 3Lua support is available through the [Lua extension](https://github.com/zed-industries/zed/tree/main/extensions/lua).
 4
 5- Tree Sitter: [tree-sitter-grammars/tree-sitter-lua](https://github.com/tree-sitter-grammars/tree-sitter-lua)
 6- Language server: [LuaLS/lua-language-server](https://github.com/LuaLS/lua-language-server)
 7
 8## luarc.json
 9
10To configure LuaLS you can create a `.luarc.json` file in the root of your workspace.
11
12See [LuaLS Settings Documentation](https://luals.github.io/wiki/settings/) for all available configuration options.
13
14```json
15{
16  "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json",
17  "runtime.version": "Lua 5.4",
18  "diagnostics.severity": {
19    "duplicate-set-field": "Hint"
20  },
21  "format.enable": true,
22  "format.defaultConfig": {
23    "indent_style": "space",
24    "indent_size": "4"
25  },
26  "workspace.library": ["../somedir/library"]
27}
28```
29
30## Formatting
31
32### LuaLS
33
34To enable auto-formatting with your LuaLS, make sure you have `"format.enable": true,` in your .luarc.json add the following to your Zed `settings.json`:
35
36```json
37{
38  "languages": {
39    "Lua": {
40      "format_on_save": "on",
41      "formatter": "language_server"
42    }
43  }
44}
45```
46
47### StyLua
48
49Alternative you can use [StyLua](https://github.com/JohnnyMorganz/StyLua):
50
511. 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).
522. Add the following to your `settings.json`:
53
54```json
55{
56  "languages": {
57    "Lua": {
58      "format_on_save": "on",
59      "formatter": {
60        "external": {
61          "command": "stylua",
62          "arguments": ["--syntax=Lua54", "-"]
63        }
64      }
65    }
66  }
67}
68```
69
70You can specify various options to StyLua either on the command line above (like `--syntax=Lua54`) or in a `stylua.toml` in your workspace:
71
72```toml
73syntax = "Lua54"
74column_width = 100
75line_endings = "Unix"
76indent_type = "Spaces"
77indent_width = 4
78quote_style = "AutoPreferDouble"
79call_parentheses = "Always"
80collapse_simple_statement = "All"
81
82[sort_requires]
83enabled = true
84```
85
86For a complete list of available options, see: [StyLua Options](https://github.com/JohnnyMorganz/StyLua?tab=readme-ov-file#options).