tsi.el
tsi.el copied to clipboard
Blank lines double-indented after `{{` and `[{`
tsx-mode
indents the line immediately following a {{
or [{
twice (all examples captured with tsi-typescript-indent-offset
= 2, |
representing the cursor):
{{
|
}}
[{
|
}]
Tokens preceding the first {
or non-newline spaces between the {
s don't appear to change this:
if(0) {{
|
}}
() => {{
|
}}
{ {
|
} }
{{
|
|
}}
Non-blank lines are indented as expected:
{{
0
}}
But any other blank lines in the {{
are still double-indented:
{{
0
|
}}
{{
|
0
}}
This is a tricky case. The tsi-typescript--get-indent-for-current-line
function has three pieces of context:
- the type of the current node at point
- the type of the parent node
- is the current line blank?
In cases like this:
{{
|
^ cursor should be here, indent 2 spaces
}}
the context is:
- current node type:
statement_block
- parent node type:
statement_block
- is current line blank?: yes
However the following has the same context:
{
{
|
^ cursor should be here, indent 4 spaces
}
}
The context is the same as the first example:
- current node type:
statement_block
- parent node type:
statement_block
- is current line blank?: yes
So if we fix the first case, we break the second case.
One solution might be to add a fourth piece of context:
- are the parent and current nodes on the same line?
That way we could differentiate between the two cases here. I'll play with this.
I tend not to notice these cases because prettier will indent these scenarios on multiple lines:
[
{
}
]
Still both are valid so it's definitely worth fixing this IMHO.