NOTE: All contents here are highly unstable.
Types of nodes considered as an indent scope. Direct children of them should be indented one more level than the parent, except the first and last child, usually open and close delimiters.
function fn(fd)
-- I'm indented
end -- Don't indent the last 'end' delimiter
Almost the same as scope
except the last child should also be indented. This usually applies to nodes with only open delimiter.
if (1)
some_call() // should be indented
Same as scope_open
but the range of the node should be considered 'extended' to cover following empty lines.
if True:
# extended and should be indented
List of type of nodes denote the direct children which should not be indented of the indent nodes in scope
and scope_open
.
if
true
then -- 'then' should be added to 'dedent_child' of 'if_statement'
-- I'm indented
end
The node should be zero indented. Used especially to dedent macros in C to 0.
{
{
#if 1
// normal indent
#endif 1
}
}
Used especially to align node to open delimiter in Python.
def fun(a,
b): # aligned indent to open delimiter of arguments
pass
Compute indent by fallback method for this type of node. By default, 'ERROR' node is always denoted as indent_fallback
because it cannot be handled by tree-sitter.
EXPERIMENTAL. I cannot figure out an accurate description for this so just ignore this section.
someCall({
a,
}, [
b
], () => {
foo();
});
Nodes considered not exist but their children should be remained. This is similar to an unwrap operation on the node to release its children directly to its parent. Some tree-sitter syntax wraps nodes extra levels and we might want to unwrap them to make the indent calculated correctly.
const jsx = (
<div>
<div>
'jsx_text' should be unwraped to 'jsx_element'
</div>
</div>
);
The function signature is fun(ctx: YatiContext): boolean|nil
.
For the return value,
true
: Handled, but continue traversing upfalse
: Handled, and stop traversingnil
: Not handled, try other handlers
For the two types of handlers,
on_initial
: On the very beginning when the base indent node is not decided yet.on_traverse
: On the traversal process from bottom to up.
For the type of context and available field, refer to context.lua.
Example handler:
function break_on_error_node(ctx)
if ctx.node:type() == "ERROR" then
ctx:set(-1)
-- or return ctx:fallback() to use fallback method
return false
end
end
The function signature is fun(lnum: integer, computed: integer, bufnr: integer): integer
.
NOTE: Value of computed
should be added to indent of lnum
calculated by fallback method (unless you deliberately return -1 to use auto indent of vim).