Closes #34390 This PR fixes several Bash indentation issues: - Adding indentation or comment using multi cursors no longer breaks relative indentation - Adding newline now places the cursor at the correct indent - Typing a valid keyword triggers context-aware auto outdent It also adds tests for all of them. Release Notes: - Fixed various issues with handling indentation in Bash.
38 lines
2.2 KiB
TOML
38 lines
2.2 KiB
TOML
name = "Shell Script"
|
|
code_fence_block_name = "bash"
|
|
grammar = "bash"
|
|
path_suffixes = ["sh", "bash", "bashrc", "bash_profile", "bash_aliases", "bash_logout", "bats", "profile", "zsh", "zshrc", "zshenv", "zsh_profile", "zsh_aliases", "zsh_histfile", "zlogin", "zprofile", ".env", "PKGBUILD", "APKBUILD"]
|
|
line_comments = ["# "]
|
|
first_line_pattern = '^#!.*\b(?:ash|bash|bats|dash|sh|zsh)\b'
|
|
autoclose_before = "}])"
|
|
brackets = [
|
|
{ start = "[", end = "]", close = true, newline = false },
|
|
{ start = "(", end = ")", close = true, newline = true },
|
|
{ start = "{", end = "}", close = true, newline = true },
|
|
{ start = "\"", end = "\"", close = true, newline = false, not_in = ["comment", "string"] },
|
|
{ start = "'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
|
|
{ start = "do", end = "done", close = false, newline = true, not_in = ["comment", "string"] },
|
|
{ start = "then", end = "fi", close = false, newline = true, not_in = ["comment", "string"] },
|
|
{ start = "then", end = "else", close = false, newline = true, not_in = ["comment", "string"] },
|
|
{ start = "then", end = "elif", close = false, newline = true, not_in = ["comment", "string"] },
|
|
{ start = "in", end = "esac", close = false, newline = true, not_in = ["comment", "string"] },
|
|
]
|
|
|
|
auto_indent_using_last_non_empty_line = false
|
|
increase_indent_pattern = "^\\s*(\\b(else|elif)\\b|([^#]+\\b(do|then|in)\\b)|([\\w\\*]+\\)))\\s*$"
|
|
decrease_indent_patterns = [
|
|
{ pattern = "^\\s*elif\\b.*", valid_after = ["if", "elif"] },
|
|
{ pattern = "^\\s*else\\b.*", valid_after = ["if", "elif", "for", "while"] },
|
|
{ pattern = "^\\s*fi\\b.*", valid_after = ["if", "elif", "else"] },
|
|
{ pattern = "^\\s*done\\b.*", valid_after = ["for", "while"] },
|
|
{ pattern = "^\\s*esac\\b.*", valid_after = ["case"] },
|
|
{ pattern = "^\\s*[\\w\\*]+\\)\\s*$", valid_after = ["case_item"] },
|
|
]
|
|
|
|
# We can't use decrease_indent_patterns simply for elif, because
|
|
# there is bug in tree sitter which throws ERROR on if match.
|
|
#
|
|
# This is workaround. That means, elif will outdents with despite
|
|
# of wrong context. Like using elif after else.
|
|
decrease_indent_pattern = "(^|\\s+|;)(elif)\\b.*$"
|