Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Support CRLF linebreaks during replace #177

Closed
wants to merge 1 commit into from

Conversation

Rantanen
Copy link

@Rantanen Rantanen commented Oct 1, 2019

The fix here just skips any CRs within the original content. Unfortunately this means we can't use direct string slicing when constructing the final text. Instead the text is resolved with take_while call that takes new characters until enough content (as defined by span.end - span.start) has been gathered.

An alternative approach would be to implement the following:

  • CodeFix::new would...
    • Detect the line breaks in use by checking the first line break in the file.
    • Normalize the string to use LF-only linebreaks.
  • CodeFix::finish would restore the original linebreaks (if necessary) once the suggestions have been applied.

This alternative approach would have a larger impact by making changes in files that use mixed line endings. Although given this change is in the context of rustfix, I would personally argue that such change wouldn't necessarily be bad.

@Rantanen
Copy link
Author

Rantanen commented Oct 1, 2019

This is in response to #176. As mentioned in that issue, I'm not entirely sure what's the current position to the whole issue and whether rustfix is even supposed to support CRLF line endings, but given I came up with this change when looking into the issue, I figured I'd create a PR just to start a discussion on what would be the best way to fix the issue (if it should be fixed to begin with).

@Rantanen
Copy link
Author

Rantanen commented Oct 1, 2019

I'll close this PR for now. Based on the discussion in #176, I'm assuming the underlying issue should be fixed in rustc.

@Rantanen Rantanen closed this Oct 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant