Skip to content
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

Formatting sends wrong response when line endings are supposed to be changed #12540

Open
farwyler opened this issue Jun 15, 2022 · 0 comments
Open
Labels
C-bug Category: bug E-unknown It's unclear if the issue is E-hard or E-easy without digging in

Comments

@farwyler
Copy link

When line endings are changed during a formatting request, the whole document is sent to the client.

let (new_text, new_line_endings) = LineEndings::normalize(captured_stdout);
if line_index.endings != new_line_endings {
// If line endings are different, send the entire file.
// Diffing would not work here, as the line endings might be the only
// difference.
Ok(Some(to_proto::text_edit_vec(
&line_index,
TextEdit::replace(TextRange::up_to(TextSize::of(&*file)), new_text),
)))
} else if *file == new_text {

The change is correctly detected and new_text contains the changed endings.
But then to_proto::text_edit_vec subsequently changes the line endings back, because it uses the ones passed in by line_index instead of new_line_endings

So the actual TextEdit in the response contains new_text with the old line endings.

Steps to reproduce

  1. be on LF system
  2. open file with CRLF endings
  3. make document formating request
  4. if line_index.endings != new_line_endings {
    reports CRLF -> LF change and new_text contains LF endings
  5. the client receives TextEdit replacing the document but still containing CRLF endings

This results in clients receiving the whole document on each request, because they always make requests with line endings that rust-analyzer wants to convert.

@Veykril Veykril added E-unknown It's unclear if the issue is E-hard or E-easy without digging in C-bug Category: bug labels Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug E-unknown It's unclear if the issue is E-hard or E-easy without digging in
Projects
None yet
Development

No branches or pull requests

2 participants