Vscode-rust: 格式不起作用

创建于 2019-03-18  ·  14评论  ·  资料来源: rust-lang/vscode-rust

你好!

我无法让 vscode 格式化代码,错误是:

[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 通过 cmd 格式化相同的文件。

要检查或配置什么?

谢谢你!

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

P-High bug rls

最有用的评论

有关此问题的任何更新?

所有14条评论

我刚开始用 VSCode 和 rls-vscode 插件学习 Rust 并得到了同样的错误。 要检查错误消息是什么,请单击视图 > 打开视图并写入输出(面板),然后按 Enter。
运行 Ubuntu Budgie 18.04.2 LTS
rustc 1.33.0 (2aa4c46cf 2019-02-28)
rustfmt 1.0.1-stable (be13559 2018-12-10)
货物 1.33.0 (f099fe94b 2019-02-12)
rustup 1.17.0 (069c88ed6 2019-03-05)

不幸的是,这是 RLS 本身的问题。 这在列表中名列前茅,所以希望这会很快得到解决

有关此问题的任何更新?

我没有收到错误消息,但我格式化也没有任何作用

我得到了同样的错误。

你好呀

从您的项目目录中发出“货物 fmt”。 这将提供更多信息,为什么不能使用格式。
就我而言,我的工具链错过了 cargo-fmt.exe。 之后它从命令行和 vscode 中工作

我有同样的问题,“cargo fmt”工作正常,从命令行运行时没有错误。 它曾经在 VSCode 中工作直到最近,现在我每次都会收到上面报告的错误。

同样在这里, cargo fmt工作但运行Format Document给我这个错误:

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

我在用

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)

我还注意到,vscode 状态栏中的RLS [building]微调器永远不会改变,并且在我保存时除了上述错误之外没有任何输出。

我有一台运行 VS Code 1.37 的机器可以正常工作,而另一台运行 1.38.1 的机器却无法正常工作,所以它看起来像是对早期问题的回归。

给像我一样刚开始学习 Rust 的新手的一个简单警告。 您的项目中似乎需要一个 Cargo.toml 文件,以便rls-vscode格式化您的代码。

看来你的项目需要一个 Cargo.toml 文件

即使使用Cargo.toml文件也不为我工作:( 我在 macOS 10.15 上使用 VS Code 1.40.2 - 运行格式时没有显示或记录任何输出,尽管没有发生任何事情,并且使用rustfmt命令行中的

编辑:毕竟工作 - 由于在我的 VS Code 设置中被设置为默认格式化程序,Prettier 被错误地使用

当 rustfmt 失败时,我得到同样的错误。 就我而言,这似乎与 rustfmt 的这个问题有关。 特别是这段代码会导致 rustfmt 失败:

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

引起的 rls 错误非常安静。 最初我检查了设置并使用 rustup 更新了 rust(这没有帮助)。
使用 rustfmt 手动格式化会导致此错误(因此链接到 rustfmt 问题):

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.

为什么这个错误仍未修复?

此页面是否有帮助?
0 / 5 - 0 等级