-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: join lines joins two ifs into else if
#9473
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
Conversation
Is there any other place joining lines has behavior other than just joining the lines? This seems quite counterintuitive to me. |
It already removes braces and commas. If you just want to join lines, you can use the editor's built-in functionality; the whole point of this function is to be smarter. And there's really no good reason to join |
That's just syntactic, not semantic, setting aside macros for obvious reasons. Imo "no other reason you'd do that" is quite dangerous when I join lines. Personally, I overrode the editor's built-in join lines to be r-a because I expect it to be a drop-in replacement. |
Undo is just a keypress away. Still, I don't see any situation where you'd join these lines without intending this change. But I'm sure @matklad would be open to making this configurable ;) |
It's more the unexpectedness factor for me. I don't think that "join lines" should do anything but save for some syntactic cleanup. I have no issue waiting for a response, though 🙂 |
Yeah, adding a config flag should be fine. I guess, I probably should heed my own advice and proactively add flags for other bits of functionality here :) Couple of more things to do:
|
At first glance, this looks like an automated refactoring which shouldn't change semantics, but if the two predicates are not mutually exclusive, or if there are side effects, it will. So it seems like it could be a footgun for the unwary... Is there a way to tell if something is an automated refactoring or a code editing shortcut? |
@rogerdahl explicitly invoked actions are "do what I mean" rather than "do not change semantics". If the user invokes join lines (which is an explicit shortcut) between two ifs, that's a signal for the IDE that they want to join the two lines. |
Note that this behavior is now configurable: https://github.com/rust-analyzer/rust-analyzer/pull/9503/files#diff-00784dde03b1be151004f435a4ca74754cb674a9e789840e12760d8f3ac1728fR727 |
Thank you! |
bors r+
🤖