Skip to content

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

Merged
merged 1 commit into from
Feb 10, 2019

Conversation

vipentti
Copy link
Contributor

@vipentti vipentti commented Feb 9, 2019

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.

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kjeremy
Copy link
Contributor

kjeremy commented Feb 9, 2019

Other than my one question LGTM

@matklad
Copy link
Member

matklad commented Feb 10, 2019

bors r+

Thanks!

bors bot added a commit that referenced this pull request Feb 10, 2019
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]>
@bors
Copy link
Contributor

bors bot commented Feb 10, 2019

Build succeeded

@bors bors bot merged commit 7b9aefc into rust-lang:master Feb 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extra empty lines when introducing new variable
3 participants