Configure Basic Node Presets
mainTreeSJ uses a hierarchical configuration for nodes. A node configuration is composed of three main tables: both, join, and split.
both: Contains settings applied to both split and join modes. This is the base configuration.join: Contains settings used specifically when joining nodes (e.g., adding spaces in brackets or inserting separators like;). These settings overridebothif keys overlap.split: Contains settings used specifically when splitting nodes (e.g., indentation rules). These settings overridebothif keys overlap.
Key Configuration Options
both (Base Settings)
no_format_with: A list of node types (e.g.,{'comment'}) that, if present as descendants, prevent the node from being formatted.separator: The string used to separate elements (e.g.,',').last_separator: Boolean indicating if the last element should have a separator.format_empty_node: Boolean; if true, handles empty brackets or tags.recursive: Boolean; if true, nested configured nodes will also use their presets.enable: Boolean or functionfunction(tsnode: TSNode): boolean. If false, the node won't be split or joined.format_tree: Functionfunction(tsj: TreeSJ): voidfor custom tree formatting.format_resulted_lines: Functionfunction(lines: string[], tsn?: TSNode): string[]to transform resulting lines.fallback: Functionfunction(node: TSNode): voidto pass control to an external script.omit: A list of node types or functions to merge with the previous node without a new line.non_bracket_node: Boolean or table{ left = 'text', right = 'text' }for nodes that don't use brackets (likethen ... end).shrink_node: Table{ from = string, to = string }to process only a specific range within a node.disable: Boolean; if true, the node is completely removed from the language preset.target_nodes: A list of node types. If not empty, TreeSJ redirects to the found child instead of usingsplit/joinsettings.
join (Join Mode Only)
space_in_brackets: Boolean; adds space in framing brackets.space_separator: Boolean; inserts space between nodes.force_insert: A string (e.g.,;) to act as an instruction separator.no_insert_if: A list of node types whereforce_insertshould be omitted.
split (Split Mode Only)
recursive: Boolean; whether nested nodes process their presets.last_indent:'normal'(matches first line) or'inner'(matches inner nodes).inner_indent:'normal'or'inner'.
local node_type = {
both = {
no_format_with = { 'comment' },
separator = '',
last_separator = false,
format_empty_node = true,
recursive = true,
recursive_ignore = {},
enable = true,
format_tree = nil,
format_resulted_lines = nil,
fallback = nil,
omit = {},
non_bracket_node = false,
shrink_node = nil,
},
join = {
space_in_brackets = false,
space_separator = true,
force_insert = '',
no_insert_if = {},
},
split = {
recursive = false,
last_indent = 'normal',
inner_indent = 'inner',
},
disable = false,
target_nodes = {},
}