-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enter in insert mode should auto indent to scope #6939
Comments
Partial duplicate of #6044 |
Helix should automatically indent the line when inserting it, is your runtime setup correctly? |
It's sad to see this closed. My helix health is all green for Rust. Indentation almost works correctly when using I say almost because when working with the view macro in rust, it jumps to the left most indentation of the macro with Helix view! { cx,
<div>
<hr />
|
^ cursor placed here with `o`
</div>
} VSCode view! { cx,
<div>
<hr />
|
^ cursor placed here with `enter`
</div>
} When working with longer nested html, it can be quite annoying having to press o and then tab many times to get back to the correct indentation. |
Both the behavior of enter and view! { cx,
<div>
<hr />
|
^ cursor here
</div>
} I think the reason for this is that Helix will try to parse the macro as Rust and apply Rust indentation rules. @Triton171 what do you think might be happening here? |
for the html indentation looking at this: tree-sitter/tree-sitter-rust#172 we probably would need an injection for html which makes sense. Regarding your original issue that is weird cause I am also developing with leptos using helix and the first part of the Though maybe there is a way to get the indent to be the same as the line before it, instead of the injection stuff. |
Hmm I'm very curious how VSCode is doing this... I just opened a new plaintext file with VScode, and the indentation behavior is still working nicely with the view macro. |
I think there's 2 ways this could be improved:
I'd like to implement the second solution, but since there's currently 2 open PRs changing the indent code (#6768 and #5355), I'd prefer to get those merged before making additional changes to the indent heuristic. Otherwise, we'll just get unnecessary merge conflicts. |
@Triton171, since #6768 and #5355 are merged, do you plan to implement the improvement you mentioned? Or are there more pressing issues? I'm really glad to see this focus and discussion on indentation issues, as it's my main annoyance with Helix at the moment (which otherwise is really good). And of course, thanks a lot for making such an amazing tool. |
Yeah, this is the next issue I want to work on in Helix. I'll probably be busy in the next few weeks, but I'll start implementing it once I find some spare time. It's non-trivial though and there are still a few things to figure out: I initially thought that we could just compare the indentation to the previous line. Having thought a bit more about it, this is probably not the best way to do it. For example, in the following C++ code we'd ideally use the start of the function call (i.e. the second line) as a baseline for indentation, since the following lines are aligned and provide no useful information on the indent level. In general, one could maybe choose the first predecessor or ancestor that starts at the beginning of a line but I'm not sure if this is always what we want (we should maybe also take into account int main() {
some_fn_with_many_args(std::string arg1,
std::vector<int> arg2,
unsigned long long arg2); // Assume that we want to insert a newline after this
} Also, comparing indents is not always feasible, especially when things like alignment are involved (as in the example above). If anyone has thoughts on these issues, please let me know, fresh ideas are always helpful. |
Addressed by #8307 |
When in insert mode, pressing enter to go to a new line places the cursor at the very start of the line, but it would be nice if the cursor automatically inserted indentations to match the scope.
Helix current behaviour
VSCode behaviour
Additionally, when closing a scope in helix, the closing bracket is placed where the cursor is, but in VSCode it auto indents/dedents to put the closing bracket in the correct location.
Helix
}
is inserted at the same location as the cursor.simplescreenrecorder.mp4
VSCode
}
is inserted at the correct indentation, despite the cursor position.simplescreenrecorder-.2.mp4
The text was updated successfully, but these errors were encountered: