-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Implement "Indent Model" #4182
Comments
Yeah, open line / newline / backspace all can benefit from indentation info... There are two pieces to the puzzle:
Heck, I think we should have this sooner rater than later, as it seems like our |
I have to say that the behavior described in the issue seems like something that should be handled by the editor and not be language-specific, but maybe I'm misunderstanding it 🤔 |
It has to be language specific I think. For example, here's some Kotlin code
Here, the Also, unrelated, but the gutter icons in IntelliJ are soooo much better than code lens :( Like this little recursion swirly it's just cute, and we can't have that in VS Code TT |
I think it would be a bad idea to implement this in VSCode for the same reason that messing with multiline commends was a bad idea:
|
VSCode already does this. For Rust it often produces unexpected or plain wrong results like the following though: let a = b
.c();<|> Pressing enter gives: let a = b
.c();
<|> That is too much indentation. Even when you already deindented the next line pressing enter decides that it needs to indent anyway: let a = b
.c();
<|> gives let a = b
.c();
<|> This is annoying. |
Not sure exactly what you mean by "this", but it does seem that VSCode does some limited language-specific indentation. It is controlled by It is regex based, and the actions are limited to the following, plus appending text (e.g.
I don't think it is quite powerful enough to be useful in your example because you can only look back one line. On reflection I think you are right that it would be nice to fix it, but I don't think the best way is by intercepting ever keypress in the language server because of the performance issues we've already seen. |
As of vscode 1.53.0 |
…emBits fix: Suppress extra indent after the end of field and function chains (spurred on by <#4182 (comment)>) Caveat that this doesn't work for after tail expressions, although there shouldn't be anything after those anyways. This also complicates when to reload the language configuration by nature of now always having a language configuration applicable. Examples of indentation fixes: ```rs fn main() { println!("Hello!"); // < enter here! // ... indents down here fs::read_to_string("soup") // < enter here! // ... still indents down here :( .map(|_| ()) .map(|_| ()) // < enter here! // ... still indents down here :D .map_err(|_| ()) .unwrap(); // < enter here! // ... indents down here :D // ... and subsequent enters stay at the same indent 0.0f64 .to_radians() .to_radians() .to_radians() // force semi on a new line ; // < enter here! // ... indents down here :D } fn tail_end() -> i32 { 0i32.wrapping_abs() .wrapping_abs() .wrapping_abs() .wrapping_abs() // < enter here! // ... still indents here 🤷 } ```
I didn't know that backspace could be improved. How wrong I was! I hope JetBrains roll out Clion backspace handling across all their products. I'd also love to see it in Rust Analyzer.
There's already special enter key handling so backspace should be possible...
I think the rules are that the first backspace takes you up a level in indentation, but then the second gobbles up all the whitespace to the start of the line and the line brake so that it appends onto the end of the previous line. This turns out to be what I wanted to do so much of the time - it feels so natural.
Small things make such a difference. Well done Clion for bringing a better backsapce to the world.
The text was updated successfully, but these errors were encountered: