Skip to main content

Overview

GLuaLS includes an opinionated Lua formatter. Format the current file with Shift+Alt+F (or right-click → Format Document).

Built-in presets

GLuaLS includes three presets for common GMod style choices:
PresetDescription
defaultStandard, no specific style
cfcFollows CFC-Servers style guidelines
customUse only styleOverrides
Set the preset in .gluarc.json:
Use the settings menu instead of editing the JSON file directly. This helps you avoid config mistakes.
.gluarc.json
{
  "format": {
    "preset": "default"
  }
}

Style overrides

Use styleOverrides to change individual rules within a preset:
Use the settings menu instead of editing the JSON file directly. This helps you avoid config mistakes.
.gluarc.json
{
  "format": {
    "preset": "default",
    "styleOverrides": {
      "indent_style": "tab",
      "indent_size": 4,
      "tab_width": 4,
      "max_line_length": 120,
      "trailing_table_separator": "smart",
      "call_arg_parentheses": "keep"
    }
  }
}

Key style options

OptionValuesDescription
indent_style"tab", "space"Indentation mode
indent_size18Number of spaces per indent level (when using spaces)
tab_width18Visual width of tabs
quote_style"none", "single", "double"Preferred quote style for string literals
call_arg_parentheses"keep", "remove", "remove_table_only", "remove_string_only", "always"How to handle parentheses around single-string/table call args
max_line_lengthintegerLine wrap threshold
trailing_table_separator"keep", "never", "always", "smart"Trailing separator in table constructors
See Configuration: Formatting for the full list.

External formatter

Use an external formatting tool, such as stylua or GLuaFixer, instead of the built-in formatter:
Use the settings menu instead of editing the JSON file directly. This helps you avoid config mistakes.
.gluarc.json
{
  "format": {
    "externalTool": {
      "program": "stylua",
      "args": ["-"],
      "timeout": 10
    }
  }
}
The external formatter receives file content over stdin and must write the formatted result to stdout.

EditorConfig

GLuaLS can read .editorconfig indent settings. Those values can override matching styleOverrides entries based on your priority setting between .editorconfig and .gluarc.json.

Format on save

Enable format-on-save in VS Code:
VS Code settings
{
  "editor.formatOnSave": true,
  "[lua]": {
    "editor.defaultFormatter": "Pollux.gmod-glua-ls"
  }
}