rust-lang / vscode-rust

Rust extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=rust-lang.rust
Other
1.39k stars 166 forks source link

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

Open skondrashov opened 3 years ago

skondrashov commented 3 years ago

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.

lnicola commented 3 years ago

Do you also see that when running cargo fmt?

skondrashov commented 3 years ago

@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.

lnicola commented 3 years ago

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.

skondrashov commented 3 years ago

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)

lnicola commented 3 years ago

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).

skondrashov commented 3 years ago

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?

lnicola commented 3 years ago

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.

skondrashov commented 3 years ago

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!