Skip to content

Commit 4f71041

Browse files
FringaleMrSubidubi
andauthored
Fix elseif / else indentation and support incomplete structures (#42)
Closes #36: `elseif` / `else` statements are now correctly outdented, with the following line now also indented as expected. This PR leverages the `indent_pattern` configuration available to language extensions, similar to other extensions (Ruby, Python, Julia, Elixir) that work around tree-sitter indentation limitations. Additionally, it provides fallback indentation for control structures and function definitions when the syntax tree is temporarily incomplete (e.g. an `if` statement without its closing `end`), which is especially useful when not using code snippets. These cases cannot yet be handled by tree-sitter alone. See the [Julia extension](https://github.com/JuliaEditorSupport/zed-julia/blob/main/languages/julia/config.toml) for related rationale. Co-authored-by: Finn Evers <finn@zed.dev>
1 parent 953af8c commit 4f71041

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

languages/lua/config.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@ brackets = [
1212
{ start = "'", end = "'", close = true, newline = false, not_in = ["string"] },
1313
]
1414
collapsed_placeholder = "--[ ... ]--"
15+
16+
# Fallback indent rules to complement tree-sitter.
17+
# Handle incomplete structures (e.g. before typing `end`).
18+
increase_indent_pattern = "^\\s*(if|elseif|else|do|while|for|repeat|((local|global)\\s+)?function|.+=\\s*function|.*[,(]\\s*function)\\b"
19+
20+
# Fallback outdent rules to complement tree-sitter.
21+
# Fix `elseif` / `else` handling, and outdent `end` / `until` even when the structure is incomplete.
22+
# Avoids relying on `valid_after` contexts, which depend on tree-sitter queries (`@start.*` captures).
23+
decrease_indent_pattern = "^\\s*(elseif|else|end|until)\\b"

0 commit comments

Comments
 (0)