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

[regression] "code":-32603,"message":"Reformat failed to complete successfully" #1397

Closed

Description

@norru

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ù <nigu.orru@gmail.com>"]

[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}
> 

Activity

  1. changed the title [-]test[/-] [+]Minor errors cause formatting to fail in cases where `rustfmt` would succeed[/+] on Mar 13, 2019
  2. Xanewok commented on Mar 17, 2019

    @Xanewok
    Contributor

    Thanks for the report! Could you provide a small code example if possible, please?

  3. norru commented on Mar 17, 2019

    @norru
    Author

    I'll see what I can do. Unfortunately, I cannot share the actual project.

    EDIT: added simple repro case to description.

  4. norru commented on Mar 18, 2019

    @norru
    Author

    It is however very easy to reproduce:

    • open a file from any project which does not contain errors
    • artificially create an error in the file, for instance prepending XXX to any struct name
    • save file
    • wait for the IDE to receive compilation status from RLS
    • attempt to format the affected file through RLS
    • check the RLS logs. The "reformat failed to complete successfully" should be there.
  5. norru commented on Mar 28, 2019

    @norru
    Author

    Unable to reproduce for technical reasons (not verified fixed!)

  6. reopened this on Mar 28, 2019
  7. norru commented on Mar 28, 2019

    @norru
    Author
    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'
    
  8. bstaletic commented on Mar 30, 2019

    @bstaletic

    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( );
    }
    • RLS log:
    [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\"}]}"
    
  9. norru commented on Mar 30, 2019

    @norru
    Author

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

  10. bstaletic commented on Mar 30, 2019

    @bstaletic

    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 fmt or rustfmt the project?

    Both of those commands worked correctly.

  11. norru commented on Mar 30, 2019

    @norru
    Author

    @bstaletic. If it is the case, then it's fine - If rls fails formatting when rustfmt works then it's the same bug. Thanks!

  12. norru commented on Apr 15, 2019

    @norru
    Author

    This is still open as for nightly-2019-04-14

  13. norru commented on Apr 15, 2019

    @norru
    Author

    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ù <nigu.orru@gmail.com>"]
    # edition = "2018"
    
    [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}
    > 
    
  14. changed the title [-]Minor errors cause formatting to fail in cases where `rustfmt` would succeed[/-] [+]"code":-32603,"message":"Reformat failed to complete successfully"[/+] on Apr 17, 2019
  15. changed the title [-]"code":-32603,"message":"Reformat failed to complete successfully"[/-] [+][regression] "code":-32603,"message":"Reformat failed to complete successfully"[/+] on Apr 17, 2019
  16. norru commented on May 16, 2019

    @norru
    Author

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

  17. nox commented on Jun 10, 2019

    @nox

    I can confirm that this happens.

  18. Barugon commented on Jul 10, 2019

    @Barugon

    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.

  19. mredaelli commented on Jul 11, 2019

    @mredaelli

    Same here in vim using coc.nvim

  20. norru commented on Jul 15, 2019

    @norru
    Author

    Still open in rls 1.37.0 (124483d 2019-07-01)

  21. Xanewok commented on Jul 15, 2019

    @Xanewok
    Contributor

    This will be alleviated by #1513

  22. norru commented on Sep 6, 2019

    @norru
    Author

    Fixed by #1533 and #1513

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions