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

Format not work #534

Open
aleksanderd opened this issue Mar 18, 2019 · 16 comments
Open

Format not work #534

aleksanderd opened this issue Mar 18, 2019 · 16 comments
Labels
bug P-High rls Issue related to the RLS itself rather than the extension

Comments

@aleksanderd
Copy link

Hi!

I can not get vscode to format code, the error is:

[Trace - 9:32:34 PM] Received response 'textDocument/formatting - (15)' in 0ms. Request failed: Reformat failed to complete successfully (-32603).
[Error - 9:32:34 PM] Request textDocument/formatting failed.
  Message: Reformat failed to complete successfully
  Code: -32603 

rustftm via cmd formats same file ok.

what to check or configure?

thank you!

rustc 1.33.0 (2aa4c46cf 2019-02-28)
rustfmt 1.0.1-stable (be13559 2018-12-10)
cargo 1.33.0 (f099fe94b 2019-02-12)
rustup 1.17.0 (069c88ed6 2019-03-05)

@gitowiec
Copy link

gitowiec commented Apr 3, 2019

I just started learning Rust with VSCode and rls-vscode plugin and got the same error. To check what is the error message, click View > Open View and write Output (panel) then press Enter.
Running Ubuntu Budgie 18.04.2 LTS
rustc 1.33.0 (2aa4c46cf 2019-02-28)
rustfmt 1.0.1-stable (be13559 2018-12-10)
cargo 1.33.0 (f099fe94b 2019-02-12)
rustup 1.17.0 (069c88ed6 2019-03-05)

@Xanewok Xanewok added bug rls Issue related to the RLS itself rather than the extension labels Apr 7, 2019
@Xanewok
Copy link
Member

Xanewok commented Apr 7, 2019

Unfortunately, this is an issue with RLS itself. That's high on the list so hopefully this will be soon resolved

@Xanewok Xanewok added the P-High label Apr 7, 2019
@zombiezen
Copy link

Is the upstream issue rust-lang/rls#1397?

@iambudi
Copy link

iambudi commented Jul 21, 2019

Any update about this issue?

@Dan-True
Copy link

I don't get an error, but I format does nothing on my end either

@Licenser
Copy link

Licenser commented Sep 9, 2019

I got the same error.

@fopsdev
Copy link

fopsdev commented Sep 13, 2019

Hi there

Issue a "cargo fmt" from within your project dir. This will give more information why formatting can not be used.
In my case my toolchain missed the cargo-fmt.exe. after that it worked from commandline and from within vscode

@cisaacson
Copy link

I have the same issue and "cargo fmt" works fine, no error when I run from the command line. It used to work until very recently within VSCode too, now I get the error reported above every time.

@lukad
Copy link

lukad commented Sep 26, 2019

Same here, cargo fmt works but running Format Document gives me this error:

[Error - 4:45:32 PM] Request textDocument/formatting failed.
  Message: Reformat failed to complete successfully
  Code: -32603

I am using

rustc 1.37.0 (eae3437df 2019-08-13)
rustfmt 1.3.0-stable (d3345024 2019-06-09)
cargo 1.37.0 (9edd08916 2019-08-02)

I also noticed that the RLS [building] spinner in vscode's status bar never changes and there is no output except the above error when I save.

@cisaacson
Copy link

I have one machine running VS Code 1.37 that works properly, and another running 1.38.1 that does not work, so it looks like it was a regression from the earlier issue.

@Soreine
Copy link

Soreine commented Oct 20, 2019

A simple warning for the fellow newbies who are just starting to learn Rust like me. It seems that you need a Cargo.toml file in your project so that rls-vscode formats your code.

@valin4tor
Copy link

valin4tor commented Nov 28, 2019

It seems that you need a Cargo.toml file in your project

Not working for me even with a Cargo.toml file :( I'm using VS Code 1.40.2 on macOS 10.15 - not getting any output displayed or logged when I run format, though nothing is happening, and using rustfmt from the command line works fine.

Edit: working after all - Prettier was being used incorrectly due to being set as the default formatter in my VS Code settings

@Skasselbard
Copy link

I get the same error when rustfmt fails. In my case this seems to be related to this issue from rustfmt. In particular this code cause rustfmt to fail:

match var.name{
    name if 
        //BAD COMMENT causes fmt error
        name.contains("smth")
        // other comment
        | name.contains("smth else") => {true}
    _ => false,
}

The caused rls error is quite silent. Initially I checked the settings and updated rust with rustup (which was of no help).
Manualy formating with rustfmt leads to this error (hence the link to the rustfmt issue):

rustfmt /path/to/file.rs
error[internal]: left behind trailing whitespace
   --> /path/to/file.rs:157:157:19
    |
157 |             name if 
    |                    ^
    |

warning: rustfmt has failed to format. See previous 1 errors.

@tifrel
Copy link

tifrel commented Sep 11, 2021

Since I do no longer expect this to get fixed, I propose to install statiolake.vscode-rustfmt. So far, I have no compatibility issues with the official rust extension, and get format on save :)

@lnicola
Copy link
Member

lnicola commented Sep 11, 2021

Using rust-analyzer (the stand-alone extension) should also work.

@DriesVerb
Copy link

If your rust-analyzer does not work try adding this to your settings.json

"[rust]": { "editor.defaultFormatter": "rust-lang.rust-analyzer" },

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug P-High rls Issue related to the RLS itself rather than the extension
Projects
None yet
Development

No branches or pull requests