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

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

Open
skondrashov opened this issue Jul 21, 2021 · 8 comments
Open

Comments

@skondrashov
Copy link

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
Copy link
Member

lnicola commented Jul 21, 2021

Do you also see that when running cargo fmt?

@skondrashov
Copy link
Author

@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
Copy link
Member

lnicola commented Jul 21, 2021

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
Copy link
Author

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
Copy link
Member

lnicola commented Jul 21, 2021

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
Copy link
Author

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
Copy link
Member

lnicola commented Jul 21, 2021

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
Copy link
Author

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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants