vscode-rust icon indicating copy to clipboard operation
vscode-rust copied to clipboard

Formatting removes blank lines depending on if they have spaces on them

Open skondrashov opened this issue 4 years ago • 8 comments

Something like:

struct A {}

#[derive(Debug)]
struct B {}

With a space on line 2, line 2 gets removed, but without a space, it stays. I'm not entirely sure what tool this issues is related to but it's very easy to reproduce on my setup and it seems I'm just using this extension to format and nothing else.

skondrashov avatar Jul 21 '21 03:07 skondrashov

Do you also see that when running cargo fmt?

lnicola avatar Jul 21 '21 09:07 lnicola

@lnicola No, cargo fmt works fine (just strips the whitespace). That runs rustfmt, right? I opened an issue on their board initially because I thought it was their issue, but then they rightly said it was not, and I can't figure out what's causing it. I have yet to replicate it with a terminal command.

skondrashov avatar Jul 21 '21 17:07 skondrashov

Yeah, I tried to reproduce it, but thought you might have a different rustfmt version.

I'm not sure why RLS would do this -- I thought it links to the rustfmt crate, but I might be wrong.

lnicola avatar Jul 21 '21 17:07 lnicola

I just tried out of curiosity, and if you have "trim trailing whitespace" on in the vscode settings, this won't happen, since it trims the whitespace first before running whatever formatter (which is also a nice workaround for me to use :p)

skondrashov avatar Jul 21 '21 17:07 skondrashov

Yeah, that's a good workaround.

But may I suggest giving https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer a spin? It does have some limitations, but some users are quite happy with it (and it auto-formats by running rustfmt, for better or worse).

lnicola avatar Jul 21 '21 17:07 lnicola

I used rust-analyzer before, and I don't remember why I switched. I do just want to support the most popular extension because it's a barrier to entry if the default option for new Rust developers is just worse... I'm a little confused why you'd recommend not using the extension as a solution to the issue, are you not affiliated with this project?

skondrashov avatar Jul 21 '21 18:07 skondrashov

I'm a little confused why you'd recommend not using the extension as a solution to the issue, are you not affiliated with this project?

I'm a rust-analyzer contributor. More often than not I refrain to advertise it, but on the other hand, a lot of new users have trouble with vscode-rust and don't necessarily realize there's an alternative.

rust-analyzer will replace RLS "some day", and currently has a more regular release schedule. Of course, it might not work well for you, but if that's the case please file an issue.

lnicola avatar Jul 21 '21 18:07 lnicola

I guess we're both looking for the same thing, I'll try rust-analyzer and contribute feedback there if I figure out why I moved away in the first place. This issue certainly doesn't happen there. Thanks!

skondrashov avatar Jul 21 '21 19:07 skondrashov