Skip to main content

Overview

The format section controls how the language server formats Lua files. Use a built-in preset, customize individual style rules, or delegate formatting to an external tool like StyLua.

Top-level options

OptionTypeDefaultDescription
format.presetstring"default"Built-in style preset: "default", "cfc", "custom"
format.configPrecedencestring"preferEditorconfig"How to resolve conflicts between .gluarc.json style settings and .editorconfig. Options: "preferEditorconfig", "preferGluarc"
format.styleOverridesobject | nullnullFine-grained overrides applied on top of the selected preset
format.externalToolobject | nullnullDelegate formatting of entire files to an external formatter
format.externalToolRangeFormatobject | nullnullExternal formatter for range (selection) formatting
format.useDiffbooleanfalseApply changes using a diff algorithm to minimise edits

Presets

PresetDescription
"default"Standard style matching the EmmyLua Analyzer defaults
"cfc"CFC Labs style (common in community GMod development)
"custom"Starts from a clean slate. Set all rules in styleOverrides

External formatter

Delegate all formatting to an external tool:
.gluarc.json
{
  "format": {
    "externalTool": {
      "program": "stylua",
      "args": ["--stdin-filepath", "$FILENAME", "-"],
      "timeout": 5000
    }
  }
}
GLuaLS passes the file contents through stdin. The formatter writes the result to stdout.

Style overrides

styleOverrides keys use snake_case matching the EmmyLuaCodeStyle style. They are applied on top of the selected preset.
This page shows common settings. For the complete list, inspect the JSON schema at crates/glua_code_analysis/resources/schema.json under EmmyrcFormatStyleOverrides.

Basic

KeyTypeDescription
indent_stylestring"tab" or "space"
indent_sizeintegerSpaces per indent level
tab_widthintegerVisual display width of a tab character
quote_stylestring"none", "single", "double"
max_line_lengthinteger | stringColumn limit. Use "unset" to disable
end_of_linestring"crlf", "lf", "cr", "auto", "unset"
table_separator_stylestring"none", "comma", "semicolon", "only_kv_colon"
trailing_table_separatorstring"keep", "never", "always", "smart"
call_arg_parenthesesstring"keep", "remove", "remove_table_only", "remove_string_only", "always"
detect_end_of_linebooleanDetect line ending from file content
insert_final_newlinebooleanEnsure file ends with a newline
end_statement_with_semicolonstring"keep", "always", "same_line", "replace_with_newline", "never"
continuation_indentintegerExtra spaces for continuation lines

Space

KeyTypeDescription
space_around_table_field_listbooleanSpaces inside table braces: { x = 1 }
space_before_function_open_parenthesisbooleanSpace before ( in function declarations
space_before_function_call_open_parenthesisbooleanSpace before ( in calls
space_inside_function_call_parenthesesbooleanSpaces inside call parentheses
space_inside_function_param_list_parenthesesbooleanSpaces inside param list parentheses
space_inside_square_bracketsbooleanSpaces inside []
space_before_open_square_bracketbooleanSpace before [
space_before_inline_commentinteger | stringSpaces before -- inline comment, or "keep"
space_after_comment_dashbooleanSpace after -- in comments
ignore_spaces_inside_function_callbooleanPreserve existing spacing in call args

Operator space

KeyTypeDescription
space_around_math_operatorbooleanSpaces around +, -, *, /, etc.
space_after_commabooleanSpace after ,
space_around_concat_operatorboolean | stringSpaces around ... Also accepts "none", "always", "no_space_asym"
space_around_logical_operatorbooleanSpaces around and, or, not
space_around_assign_operatorboolean | stringSpaces around =. Also accepts "none", "always", "no_space_asym"

Alignment

KeyTypeDescription
align_call_argsbooleanAlign multiline call arguments
align_function_paramsbooleanAlign multiline function parameters
align_continuous_assign_statementstring"true", "false", "always"
align_continuous_rect_table_fieldstring"true", "false", "always"
align_continuous_line_spaceintegerMax blank-line gap for an aligned block
align_if_branchbooleanAlign if/elseif/else branches
align_array_tablestring"none", "always", "contain_curly"
align_continuous_inline_commentbooleanAlign consecutive inline comments
align_chain_exprstring"none", "always", "only_call_stmt"

Indent

KeyTypeDescription
never_indent_before_if_conditionbooleanDon’t indent before if conditions
keep_indents_on_empty_linesbooleanPreserve indentation on empty lines
allow_non_indented_commentsbooleanAllow comments to remain non-indented

Line spacing

These keys accept string expressions: "keep", "fixed(n)", "min(n)", "max(n)".
KeyDescription
line_space_after_if_statementLines after if blocks
line_space_after_do_statementLines after do blocks
line_space_after_while_statementLines after while blocks
line_space_after_for_statementLines after for blocks
line_space_after_function_statementLines after function statements
line_space_after_local_or_assign_statementLines after local/assignment statements
line_space_after_expression_statementLines after expression statements
line_space_after_commentLines after comments
line_space_around_blockLines around blocks

Line break

KeyTypeDescription
break_all_list_when_line_exceedbooleanBreak all list items once line exceeds max length
auto_collapse_linesbooleanAuto-collapse short multiline expressions
break_before_bracesbooleanOpening braces on new line
break_multiline_call_expression_listbooleanEach arg on its own line for already-multiline calls

Preference

KeyTypeDescription
remove_call_expression_list_finish_commabooleanRemove trailing comma in call arg lists
remove_redundant_condition_parenthesesbooleanRemove redundant parentheses around single-line conditions

VSCode extension settings

GLuaLS does not provide gluals.format.* VS Code settings. Configure formatting through .gluarc.json. You can enable format-on-save with these built-in VS Code settings:
VSCode SettingDescription
editor.formatOnSaveEnable format on save (built-in VS Code setting)
[lua].editor.defaultFormatterSet to Pollux.gmod-glua-ls

Example

.gluarc.json
{
  "format": {
    "preset": "cfc",
    "configPrecedence": "preferGluarc",
    "styleOverrides": {
      "max_line_length": 110,
      "indent_style": "tab",
      "trailing_table_separator": "smart"
    }
  }
}