-
Notifications
You must be signed in to change notification settings - Fork 295
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
Format document sometimes adds blank newlines between every line #4865
Comments
It's been a while (some months) I encounter this problem too. The quickest fix I have found is to execute the command : Reload Window. |
I have just tested and switching the files to CRLF prevent the bug from happening but switching back to LF and the bug come back. |
@BeezBeez do you know of any steps to reliably reproduce it? I've tried writing some files with mixed line endings like: void main(List<String> arguments) {
File('lib/crlf.dart').writeAsStringSync('String? a1;\r\nString? a2;\r\nString? a3;\r\n');
File('lib/lf.dart').writeAsStringSync('String? a1;\nString? a2;\nString? a3;\n');
File('lib/mixed.dart').writeAsStringSync('String? a1;\r\nString? a2;\nString? a3;\r\n');
} However they all format normally and no extra lines are inserted. |
Scratch that - I think I have a repro. I switched to the latest bleeding-edge Dart SDK (not stable) and it seems to trigger in my
Edit: the repro stopped after restarting VS Code. Seems like there are some specific actions contributing to this. Same open file, same format request, different result:
Edit2: Ok, repros if I reload VS Code, save crlf.dart, then save lf.dart. Maybe something being cached is affecting the newlines between the files? |
I figured this out, and I think there are two parts to it:
I'm working on a fix to the first (to never reuse the formatter), but have also opened dart-lang/dart_style#1337. I'll do some testing of the second issue and file a VS Code issue if appropriate after. |
Dart fix is open at https://dart-review.googlesource.com/c/sdk/+/340220 and I've opened microsoft/vscode#200157 about the weird VS Code behaviour that resulted in the attempt to change LF to CRLF resulting in actual blank lines. |
…atted with \n if a previous file was formatted with \r\n Caching the formatter (something we recently discussed removing) was causing issues if you formatted multiple files with different line endings. It might be a VS Code bug that "\r\n" is being rendered with a blank line in between when the document was in LF mode, but I'll investigate that separately and file an issue there if required. Fixes Dart-Code/Dart-Code#4865 Change-Id: Ib5ec5355f078bc8dd2b30440fd253663727a2b66 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340220 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Keerti Parthasarathy <keertip@google.com> Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Fixed by dart-lang/sdk@315d0b7. The fix is in the analysis server so ships with a future Dart SDK. If you're often working on files with mix line endings, two possible workarounds:
|
I've seen this a couple of times in the last few days:
format.mp4
My feeling is that it's related to having a document that is mostly LF but then you add some CRLF (for example during a merge conflict or pasting).
Here's a (zipped, to reduce the chance of anything messing with it) copy of the file from the video in the state that triggers it.
handler_execute_command.zip
And as I hit save, I reload VS Code to ensure it still occurs, but it does not. So probably there is some state involved and it's not just the file on disk. It's unclear if the issue is on the server or the client side.
The text was updated successfully, but these errors were encountered: