This error is generally emitted when there is a typo in the code causing a compilation error but also happens on "clean" code in rare cases. rustfmt is able to deal with those typos and format the code correctly, while RLS fails.
Minor errors (ie typo in ident) should not cause formatting to fail. Those errors are common during refactoring while one needs to keep the code tidy and formatted to be able to reason about it.
rustfmt run from the command line does work in these cases.
This behaviour was introduced in a recent update and has heavily disrupted my workflow. Error was not present in rls 1.34.0 (0d6f53e 2019-02-14)
If this is deemed a feature, please introduce a config option to disable it.
Trivial repro:
Cargo.toml
[package]
name = "test_format"
version = "0.1.0"
authors = ["Nicola Orr霉 <[email protected]>"]
[dependencies]
src\main.rs
fn main() {
const i: i32 = 0.5;
println!("Hello, world!");
}
[t=1555338926023] LSP4E to org.eclipse.corrosion.rls:
{"jsonrpc":"2.0","id":"60","method":"textDocument/formatting","params":{"textDocument":{"uri":"file:[...]src/main.rs"},"options":{"tabSize":4,"insertSpaces":false}}}
[t=1555338926023] org.eclipse.corrosion.rls to LSP4E:
{"jsonrpc":"2.0","error":{"code":-32603,"message":"Reformat failed to complete successfully"},"id":"60"}
$ rls --cli
Initializing (look for `progress[done:true]` message)...
> 1: InitializeResult {
capabilities: ServerCapabilities {
text_document_sync: Some(
Kind(
Incremental,
),
),
hover_provider: Some(
true,
),
completion_provider: Some(
CompletionOptions {
resolve_provider: Some(
true,
),
trigger_characters: Some(
[
".",
":",
],
),
},
),
signature_help_provider: None,
definition_provider: Some(
true,
),
type_definition_provider: None,
implementation_provider: Some(
Simple(
true,
),
),
references_provider: Some(
true,
),
document_highlight_provider: Some(
true,
),
document_symbol_provider: Some(
true,
),
workspace_symbol_provider: Some(
true,
),
code_action_provider: Some(
Simple(
true,
),
),
code_lens_provider: Some(
CodeLensOptions {
resolve_provider: Some(
false,
),
},
),
document_formatting_provider: Some(
true,
),
document_range_formatting_provider: Some(
false,
),
document_on_type_formatting_provider: None,
rename_provider: Some(
Simple(
true,
),
),
color_provider: None,
folding_range_provider: None,
execute_command_provider: Some(
ExecuteCommandOptions {
commands: [
"rls.applySuggestion-21192",
"rls.deglobImports-21192",
],
},
),
workspace: None,
},
}
{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_1","title":"Building"}}
{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_1","message":"test_format cfg(test)","title":"Building"}}
{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_1","message":"test_format","title":"Building"}}
{"jsonrpc":"2.0","method":"window/progress","params":{"done":true,"id":"progress_1","title":"Building"}}
{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_0","title":"Indexing"}}
{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"code":"E0308","message":"mismatched types\n\nexpected i32, found floating-point number\n\nnote: expected type `i32`\n found type `{float}`","range":{"end":{"character":23,"line":1},"start":{"character":20,"line":1}},"severity":1,"source":"rustc"}],"uri":"file:///home/norru/Projects/ivt/test_format/src/main.rs"}}
{"jsonrpc":"2.0","method":"window/progress","params":{"done":true,"id":"progress_0","title":"Indexing"}}
> format src/main.rs
{"jsonrpc":"2.0","error":{"code":-32603,"message":"Reformat failed to complete successfully"},"id":2}
>
Thanks for the report! Could you provide a small code example if possible, please?
I'll see what I can do. Unfortunately, I cannot share the actual project.
EDIT: added simple repro case to description.
It is however very easy to reproduce:
Unable to reproduce for technical reasons (not verified fixed!)
rls 1.34.0 (0d6f53e 2019-02-14) because it predates the regressionrls 1.35.0 (90f7ab0 2019-03-17) because of https://github.com/rust-lang/rls/issues/1409nightly because of error: some components unavailable for download: 'rls', 'clippy'
if you require these components, please install and use the latest successful build version, which you can find at https://rust-lang-nursery.github.io/rust-toolstate, for example.
rustup install nightly-2018-12-27 for channel 'nightly'
I can consistently reproduce this problem.
Cargo.toml:[package]
name = "common"
version = "0.1.0"
[dependencies]
src/main.rs:mod test;
use test::*;
fn unformatted_function( param : bool) -> bool
{ return param }
fn main()
{
create_universe( );
build_
}
Issuing textDocument/formatting fails with -32603 error code and this is in the log:
[2019-03-30T12:15:18Z TRACE rls::server] Read message `{"id": "2", "jsonrpc": "2.0", "method": "textDocument/formatting", "params": {"options": {"insertSpaces": true, "tabSize": 4}, "textDocument": {"uri": "file:///home/bstaletic/.vim/pack/bundle/start/YouCompleteMe/third_party/ycmd/ycmd/tests/rust/testdata/common/src/main.rs"}}}`
[2019-03-30T12:15:18Z TRACE rls::server] Parsed message `RawMessage { method: "textDocument/formatting", id: Str("2"), params: Object({"options": Object({"insertSpaces": Bool(true), "tabSize": Number(4)}), "textDocument": Object({"uri": String("file:///home/bstaletic/.vim/pack/bundle/start/YouCompleteMe/third_party/ycmd/ycmd/tests/rust/testdata/common/src/main.rs")})}) }`
[2019-03-30T12:15:18Z TRACE rls::server] Handling `textDocument/formatting`
[2019-03-30T12:15:18Z TRACE rls::actions::requests] Reformat: TextDocumentIdentifier { uri: "file:///home/bstaletic/.vim/pack/bundle/start/YouCompleteMe/third_party/ycmd/ycmd/tests/rust/testdata/common/src/main.rs" } None 4 true
[2019-03-30T12:15:18Z WARN rls::actions::requests] Reformat failed: ambiguous edition for `/home/bstaletic/.vim/pack/bundle/start/YouCompleteMe/third_party/ycmd/ycmd/tests/rust/testdata/common/src/main.rs`
[2019-03-30T12:15:18Z TRACE rls::server::io] response: "Content-Length: 103\r\n\r\n{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32603,\"message\":\"Reformat failed to complete successfully\"},\"id\":\"2\"}"
But if line 11 (the one that only says build_ and thus contains the error) is removed from the main.rs, the textDocument/formatting request succeeds.
main.rs:mod test;
use test::*;
fn unformatted_function( param : bool) -> bool
{ return param }
fn main()
{
create_universe( );
}
[2019-03-30T12:18:55Z TRACE rls::server] Read message `{"id": "4", "jsonrpc": "2.0", "method": "textDocument/formatting", "params": {"options": {"insertSpaces": true, "tabSize": 4}, "textDocument": {"uri": "file:///home/bstaletic/.vim/pack/bundle/start/YouCompleteMe/third_party/ycmd/ycmd/tests/rust/testdata/common/src/main.rs"}}}`
[2019-03-30T12:18:55Z TRACE rls::server] Parsed message `RawMessage { method: "textDocument/formatting", id: Str("4"), params: Object({"options": Object({"insertSpaces": Bool(true), "tabSize": Number(4)}), "textDocument": Object({"uri": String("file:///home/bstaletic/.vim/pack/bundle/start/YouCompleteMe/third_party/ycmd/ycmd/tests/rust/testdata/common/src/main.rs")})}) }`
[2019-03-30T12:18:55Z TRACE rls::server] Handling `textDocument/formatting`
[2019-03-30T12:18:55Z TRACE rls::actions::requests] Reformat: TextDocumentIdentifier { uri: "file:///home/bstaletic/.vim/pack/bundle/start/YouCompleteMe/third_party/ycmd/ycmd/tests/rust/testdata/common/src/main.rs" } None 4 true
[2019-03-30T12:18:55Z TRACE rls::actions::requests] Detected edition 2015 for file `/home/bstaletic/.vim/pack/bundle/start/YouCompleteMe/third_party/ycmd/ycmd/tests/rust/testdata/common/src/main.rs`
[2019-03-30T12:18:55Z TRACE rls::server::io] response: "Content-Length: 289\r\n\r\n{\"jsonrpc\":\"2.0\",\"id\":\"4\",\"result\":[{\"range\":{\"start\":{\"line\":0,\"character\":0},\"end\":{\"line\":12,\"character\":0}},\"newText\":\"mod test;\\n\\nuse test::*;\\n\\nfn unformatted_function(param: bool) -> bool {\\n return param;\\n}\\n\\nfn main() {\\n create_universe();\\n build_rocket();\\n}\\n\"}]}"
@bstaletic Thanks for the repro, doesn't seem to be exactly the same issue as I see though.
Does it work if you cargo fmt or rustfmt the project?
Thanks for the repro, doesn't seem to be exactly the same issue as I see though.
In that case, sorry for the noise. Should I open a new issue?
Does it work if you
cargo fmtorrustfmtthe project?
Both of those commands worked correctly.
@bstaletic. If it is the case, then it's fine - If rls fails formatting when rustfmt works then it's the same bug. Thanks!
This is still open as for nightly-2019-04-14
On nightly-2019-04-14
The minimal example is astonishingly trivial. I find hard to believe nobody has managed to reproduce this.
Cargo.toml
[package]
name = "test_format"
version = "0.1.0"
authors = ["Nicola Orr霉 <[email protected]>"]
# edition = "2018"
[dependencies]
srcmain.rs
fn main() {
const i: i32 = 0.5;
println!("Hello, world!");
}
[t=1555338926023] LSP4E to org.eclipse.corrosion.rls:
{"jsonrpc":"2.0","id":"60","method":"textDocument/formatting","params":{"textDocument":{"uri":"file:[...]src/main.rs"},"options":{"tabSize":4,"insertSpaces":false}}}
[t=1555338926023] org.eclipse.corrosion.rls to LSP4E:
{"jsonrpc":"2.0","error":{"code":-32603,"message":"Reformat failed to complete successfully"},"id":"60"}
$ rls --cli
Initializing (look for `progress[done:true]` message)...
> 1: InitializeResult {
capabilities: ServerCapabilities {
text_document_sync: Some(
Kind(
Incremental,
),
),
hover_provider: Some(
true,
),
completion_provider: Some(
CompletionOptions {
resolve_provider: Some(
true,
),
trigger_characters: Some(
[
".",
":",
],
),
},
),
signature_help_provider: None,
definition_provider: Some(
true,
),
type_definition_provider: None,
implementation_provider: Some(
Simple(
true,
),
),
references_provider: Some(
true,
),
document_highlight_provider: Some(
true,
),
document_symbol_provider: Some(
true,
),
workspace_symbol_provider: Some(
true,
),
code_action_provider: Some(
Simple(
true,
),
),
code_lens_provider: Some(
CodeLensOptions {
resolve_provider: Some(
false,
),
},
),
document_formatting_provider: Some(
true,
),
document_range_formatting_provider: Some(
false,
),
document_on_type_formatting_provider: None,
rename_provider: Some(
Simple(
true,
),
),
color_provider: None,
folding_range_provider: None,
execute_command_provider: Some(
ExecuteCommandOptions {
commands: [
"rls.applySuggestion-21192",
"rls.deglobImports-21192",
],
},
),
workspace: None,
},
}
{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_1","title":"Building"}}
{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_1","message":"test_format cfg(test)","title":"Building"}}
{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_1","message":"test_format","title":"Building"}}
{"jsonrpc":"2.0","method":"window/progress","params":{"done":true,"id":"progress_1","title":"Building"}}
{"jsonrpc":"2.0","method":"window/progress","params":{"id":"progress_0","title":"Indexing"}}
{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"diagnostics":[{"code":"E0308","message":"mismatched types\n\nexpected i32, found floating-point number\n\nnote: expected type `i32`\n found type `{float}`","range":{"end":{"character":23,"line":1},"start":{"character":20,"line":1}},"severity":1,"source":"rustc"}],"uri":"file:///home/norru/Projects/ivt/test_format/src/main.rs"}}
{"jsonrpc":"2.0","method":"window/progress","params":{"done":true,"id":"progress_0","title":"Indexing"}}
> format src/main.rs
{"jsonrpc":"2.0","error":{"code":-32603,"message":"Reformat failed to complete successfully"},"id":2}
>
After updating to rustc 1.36.0-nightly (7158ed9cb 2019-05-15) + rls 1.36.0 (5b8e99b 2019-05-01) this is now a 100% failure meaning that it is no longer possible to format within the Corrosion IDE and cargo fmt is the only way to do it.
Running cargo clean in the affected projects and restarting the IDE makes the problem not 100% again (basically back to the initial report).
I can confirm that this happens.
This is happening to me in vscode. Specifically, I was doing the Amethyst pong tutorial and when I got to the step that adds systems/paddle.rs to the project, I wasn't able to format that file. Up until then, I had no problem.
Same here in vim using coc.nvim
Still open in rls 1.37.0 (124483d 2019-07-01)
This will be alleviated by https://github.com/rust-lang/rls/pull/1513
Most helpful comment
Fixed by https://github.com/rust-lang/rls/pull/1533 and https://github.com/rust-lang/rls/pull/1513