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

format document sometimes ignored #65

Closed
sophiajt opened this issue Jun 21, 2017 · 12 comments
Closed

format document sometimes ignored #65

sophiajt opened this issue Jun 21, 2017 · 12 comments
Labels

Comments

@sophiajt
Copy link

I have two files in my project, main.rs and other.rs.

If I do 'format document' on my other.rs, it works fine. If, instead, I do format document on my main.rs, it doesn't do anything and leaves the file as is (complete with trailing spaces).

@sophiajt
Copy link
Author

Looking at the "Rust Language Server" output, I get:

[Error - 6:21:09 AM] Request textDocument/formatting failed.
  Message: Reformat failed to complete successfully
  Code: -32601

As this file builds correctly, not sure what would fail formatting.

@doxxx
Copy link

doxxx commented Jul 25, 2017

@jonathandturner I've had that happen where some of the lines in the file exceeded the default max_width setting of 100 in the rustfmt settings. I worked around the problem by creating a rustfmt.toml file in the root of my project and adding max_width = 120 to it.

@nrc
Copy link
Member

nrc commented Jul 25, 2017

Ah, that's an interesting clue - rustfmt is meant to work as a checker too, so if a line fails the width constraint it sets the exit code to a failure code. I wonder if the RLS is interpreting that as failure to run.

@doxxx
Copy link

doxxx commented Jul 25, 2017

When I use the VSCode Format Document command on a file that is already formatted, I get no error. If I add a line with just comment characters that exceeds the max_width setting in my rustfmt.toml by one, I get this error:

[Error - 6:23:00 PM] Request textDocument/formatting failed.
  Message: Reformat failed to complete successfully
  Code: -32603 

If I reduce the number of characters on that line by one, I get no error.

@doxxx
Copy link

doxxx commented Jul 25, 2017

rustfmt reports the error reasonably well:

Rustfmt failed at \\?\C:\Users\Gordon\dev\rust\raytracer\src\object.rs:13: line exceeded maximum length (maximum: 120, found: 121) (sorry)

But I guess rls doesn't parse that and just looks at the exit code.

@doxxx
Copy link

doxxx commented Jul 25, 2017

IMHO, linters and formatters should be separate tools. rustfmt should be reformatting the file to achieve the max_width setting, not simply aborting when a line exceeds that max.

@doxxx
Copy link

doxxx commented Jul 25, 2017

I take that back. It seems to only fail with that error when it can't reformat the line to reduce it below max_width. If I make a fn declaration with a long list of parameters that extends past the max_width, rustfmt will reformat the declaration to chop down, without reporting that error.

@nrc
Copy link
Member

nrc commented Oct 30, 2017

cc rust-lang/rustfmt#1977 (because we seem to need to check the exit code better in the RLS)

@nrc nrc added the P-High label Oct 30, 2017
@maskofsanity
Copy link

I get the same -32603 error code when I start a multi-line comment followed by a space and a newline. Deleting the space gets it working again. I'm on the beta channel since I couldn't get rls-preview on nightly, so I'm not sure if this is still an issue.

@DanielJoyce
Copy link

Not only does the format fail, RLS crashes and rls-vscode fails to restart it.

At the very least can that bit be made robust?

@nrc
Copy link
Member

nrc commented Apr 16, 2018

@DanielJoyce do you have a test case which reproduces this reliably? I'd like to look into this.

@nrc
Copy link
Member

nrc commented Jun 21, 2018

This should be fixed now that we've changed the rustfmt exit codes.

@nrc nrc closed this as completed Jun 21, 2018
Xanewok pushed a commit to Xanewok/rls-vscode that referenced this issue Mar 27, 2019
Added docstrings based on the language server protocol to …
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants