You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, we run indentation queries only when a new line is being inserted. However, other editors can in some cases update the indentation while typing, for example in C++ switch statements:
switch (var) {
case0: // As soon as this can be recognized as a case label, it should be outdented
}
in python if statements:
ifcondition:
do_smth()
else: # As soon as this can be recognized as an else statement, it should be outdented
or when inserting a closing curly brace } which should be outdented. CLion (basically IntelliJ for C++ development) even correctly indents multiple lines after surrounding them with curly braces (or adding something like an if statement around it):
{ // Adding these curly braces causes the entire block to be correctly indenteddo_smth();
do_smth_on_multiple_lines();
}
Implementing features like this in helix would require us to run some kind of indent query on every edit (or at least every time the syntax tree changes significantly). Because of that (and because it has the potential to be very annoying if the updated indentation is incorrect), this kind of auto-indent should probably off by default but I still think it would be very nice to support it in helix. As far as I see, there are a few different ways it could be implemented:
We could introduce a new kind of indent query "update-indent.scm" which just specifies situations in which the indent should be updated. This could either include the required update to the indentation (e.g. decrease the indentation by 1) or simply rerun the normal indent queries for the specified parts of the syntax trees. This is probably the easiest solution but it would require additional queries for all languages, for which we want to support this feature.
A different option would be to simply use the existing indent queries. The advantage to this is that we don't need additional queries. However, there are obviously some cases where the indent shouldn't be updated and we would need to exclude them: The indent computed by our heuristic may not match the indent that the user wants (either because there is a bug in the heuristic or because the file uses a non-conventional indentation style). Incorrectly updating the indentation once may be fine but if the user changes it back to what it was before, the indentation shouldn't be updated again.
One possible heuristic for this could be to only update the indentation when a new node is inserted in the syntax tree (we may also want to require that this node doesn't contain any errors). This way, the indentation is only updated once and the user is able to correct it. Additionally, it might be a good idea to check that the indentation heuristic matches the actual indentation for surrounding code. If that's not the case, it's not very likely that the heuristic can correctly predict the indentation for the part of the code that changed.
These are only some ideas and I haven't started any implementation, so let me know your thoughts on this. Also, please tell me if this is not something that helix should include out-of-the-box.
The text was updated successfully, but these errors were encountered:
Currently, we run indentation queries only when a new line is being inserted. However, other editors can in some cases update the indentation while typing, for example in C++ switch statements:
in python if statements:
or when inserting a closing curly brace
}
which should be outdented. CLion (basically IntelliJ for C++ development) even correctly indents multiple lines after surrounding them with curly braces (or adding something like an if statement around it):Implementing features like this in helix would require us to run some kind of indent query on every edit (or at least every time the syntax tree changes significantly). Because of that (and because it has the potential to be very annoying if the updated indentation is incorrect), this kind of auto-indent should probably off by default but I still think it would be very nice to support it in helix. As far as I see, there are a few different ways it could be implemented:
We could introduce a new kind of indent query "
update-indent.scm
" which just specifies situations in which the indent should be updated. This could either include the required update to the indentation (e.g. decrease the indentation by 1) or simply rerun the normal indent queries for the specified parts of the syntax trees. This is probably the easiest solution but it would require additional queries for all languages, for which we want to support this feature.A different option would be to simply use the existing indent queries. The advantage to this is that we don't need additional queries. However, there are obviously some cases where the indent shouldn't be updated and we would need to exclude them: The indent computed by our heuristic may not match the indent that the user wants (either because there is a bug in the heuristic or because the file uses a non-conventional indentation style). Incorrectly updating the indentation once may be fine but if the user changes it back to what it was before, the indentation shouldn't be updated again.
One possible heuristic for this could be to only update the indentation when a new node is inserted in the syntax tree (we may also want to require that this node doesn't contain any errors). This way, the indentation is only updated once and the user is able to correct it. Additionally, it might be a good idea to check that the indentation heuristic matches the actual indentation for surrounding code. If that's not the case, it's not very likely that the heuristic can correctly predict the indentation for the part of the code that changed.
These are only some ideas and I haven't started any implementation, so let me know your thoughts on this. Also, please tell me if this is not something that helix should include out-of-the-box.
The text was updated successfully, but these errors were encountered: