-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fix introduce var duplicating newlines #770
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
Fix introduce var duplicating newlines #770
Conversation
This fixes rust-lang#713. If the block before the statement we want to use introduce var on, had empty lines these empty lines would also be added between the let-statement and the current line where the new variable is used. This fixes that by trimming excess newlines from the start of the indent chunk and simply adding a single newline (when the chunk had newlines) between the let-statement and the current statement. If there were no newlines this matches the previous behaviour.
} else if chunk.starts_with("\n") { | ||
buf.push_str("\n"); | ||
buf.push_str(chunk.trim_start_matches("\n")); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen this in a few spots where we look for \r\n
or \n
. Is there a crate (something in std?) that can help with terminators?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to look for something in the std or any crates that would help dealing with terminators but could not find any.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should ideally convert \r\n to \n somewhere on the VFS layer, or maybe when we are constructing a syntax tree. Internals should always use \n as a line separator.
Will make an issue for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than my one question LGTM |
bors r+ Thanks! |
770: Fix introduce var duplicating newlines r=matklad a=vipentti This fixes #713. If the block before the statement we want to use introduce var on, had empty lines these empty lines would also be added between the let-statement and the current line where the new variable is used. This fixes that by trimming excess newlines from the start of the indent chunk and simply adding a single newline (when the chunk had newlines) between the let-statement and the current statement. If there were no newlines this matches the previous behaviour. Co-authored-by: Ville Penttinen <[email protected]>
Build succeeded |
This fixes #713.
If the block before the statement we want to use introduce var on, had empty
lines these empty lines would also be added between the let-statement and
the current line where the new variable is used.
This fixes that by trimming excess newlines from the start of the indent chunk
and simply adding a single newline (when the chunk had newlines) between the
let-statement and the current statement. If there were no newlines this
matches the previous behaviour.