标签: rust-analyzer

如何在 VSCode 中使用 rust-analyzer 打字时启用实时 linting?

我在 VSCode 中有 rust-analyzer 扩展。

在设置中,我只Rust-analyzer › Check On Save: Command从更改checkclippy(这应该无关紧要)。

问题是我在输入时没有看到错误,只有在我保存之后。

输入(没有错误):

打字

已保存(可以看到错误):

已保存

可以改变吗?

rust visual-studio-code rust-analyzer

5
推荐指数
1
解决办法
685
查看次数

rust-analyzer.linkedProjects 不适用于相对路径 ${workspaceFolder}。有什么解决方法吗?

  • 我有一个存储库,其中有 Cargo.tomlsub_dir/Cargo.toml (Cargo.toml 不在存储库根目录中)
  • 我正在使用我的一些计算机上的存储库。所以我需要设置rust-analyzer.linkedProjects所以我需要根据每个环境

我想避免通过机器进行配置。你知道有什么解决方法吗?

rust visual-studio-code rust-analyzer

5
推荐指数
1
解决办法
3690
查看次数

有没有办法阻止 rust-analyzer 使“非活动”代码变暗?

我目前正在制作一个嵌入式系统。为此,我有 2 个不同的恐慌处理程序,具体取决于它是正常运行还是作为测试运行。 #[cfg(test)] 对于测试恐慌处理程序和 #[cfg(not(test))] 正常恐慌处理程序。

rust-analyzer 说:由于 #[cfg] 指令,代码处于非活动状态:测试已启用

并使该功能变灰。测试从未明确设置,因此我不能只是更改它,而且我不想禁用工作区中灰显的非活动代码。

有没有办法禁用 rust-analyzer 检查测试 cfg,或者仅针对此功能禁用灰色

我尝试查找有关测试标志的信息,但找不到任何信息,如果它很重要,我正在使用 VS Code

rust rust-analyzer

5
推荐指数
1
解决办法
2276
查看次数

我可以告诉 rust-analyzer 使用 WSL rust 安装吗?

https://www.rust-lang.org/tools/install指出可以使用 WSL 安装 Rust,效果很好。然而, VSCode 的 rust-analyzer 插件默认只能利用主机系统的 rust 安装,因为它在启动过程中找不到货物安装,并失败并显示以下消息:

[ERROR rust_analyzer::main_loop] FetchWorkspaceError:
rust-analyzer failed to load workspace: "cargo" "--version" failed: program not found
Run Code Online (Sandbox Code Playgroud)

有没有办法配置 rust-analyzer 以使用我的 WSL Rust 安装?

当然,另一种选择是使用开发容器,但这对于我正在从事的特定项目来说会非常麻烦。

rust visual-studio-code rust-analyzer

5
推荐指数
0
解决办法
1565
查看次数

rust-analyzer:无法写入请求:管道损坏(操作系统错误 32)

尽管构建项目时没有错误或警告,rust-analyzer但 VS Code出现此错误。cargo build

rustc版本:1.54.0

我想保留“稳定”rustc版本,而不是切换到“夜间”版本。

rust visual-studio-code rust-analyzer

4
推荐指数
1
解决办法
3595
查看次数

自动补全不适用于模块文件中的 Rust(与代码)

在我的 main.rs 中,我可以很好地完成代码。但我没有在我的模块文件中得到它。

我的文件夹结构如下所示:

src/
|___game_components/
|   |___card.rs
|___game_components.rs
|___main.rs
Run Code Online (Sandbox Code Playgroud)

该程序构建并运行得很好(除了一些未使用的警告)。str当编辑我的 main.rs 文件时,我得到了,rand和我的结构的代码完成Card。然而,当编辑我的任一 card.rs 时,我根本没有得到任何代码完成,甚至对于该文件中定义的 Card 结构也是如此。

我尝试重新安装 rust-analyzer 并运行rustup update,但没有运气。

我错过了什么,或者某个地方有错误吗?

编辑:添加文件内容

主要.rs:

pub mod game_components;

use game_components::card::Card;

fn main() {
    println!("{:?}", Card::new(5));
}
Run Code Online (Sandbox Code Playgroud)

游戏组件.rs:

pub mod card;
Run Code Online (Sandbox Code Playgroud)

卡.rs:

const FACES: [&str; 13] = [
    "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace",
];
const SUITS: [&str; 4] = ["Hearts", "Clubs", "Diamonds", "Spades"];

#[derive(Debug)]
pub struct …
Run Code Online (Sandbox Code Playgroud)

code-completion rust visual-studio-code rust-analyzer

4
推荐指数
1
解决办法
4441
查看次数

为什么我会看到 VSCode 中的 let 语句中添加了“: String”?

当我在 VSCode 中输入以下内容时:

let mut guess = String::new();
Run Code Online (Sandbox Code Playgroud)

我看到它变成了:

let mut guess: String = String::new();
Run Code Online (Sandbox Code Playgroud)

为什么会发生这种情况?

rust visual-studio-code rust-analyzer

3
推荐指数
1
解决办法
547
查看次数

如何在 vscode 中隐藏 main() 文本上方的“运行 | 调试”?

我通常直接从终端运行我的应用程序,因此此文本只会增加一些噪音。知道如何删除它吗?

在此输入图像描述

rust visual-studio-code rust-analyzer

3
推荐指数
1
解决办法
584
查看次数

Proc 宏“main”未扩展 + Rust 分析器未生成服务器

我将这两个问题合二为一,因为它们可能是相关的。几天前,我开始在 main 函数之前的 [#actix_rt::main] 行中出现此错误:

proc macro `main` not expanded: cannot find proc-macro server in sysroot `C:\Users\zerok\.rustup\toolchains\stable-x86_64-pc-windows-gnu`
Run Code Online (Sandbox Code Playgroud)

与此同时,在 VSCode 中,我的 rust-analyzer 扩展开始失败。我卸载了它,重新启动 VSCode,然后重新安装。它不断地给出同样的错误:

Failed to spawn one or more proc-macro servers.
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

rust rust-proc-macros rust-analyzer

3
推荐指数
1
解决办法
8105
查看次数

为什么 let 绑定中不允许使用顶级 or 模式?

fn foo(ok: bool) -> Result<i32, i32> {
    if ok { Ok(0) } else { Err(0) }
}

fn main() {
    let Ok(x) | Err(x) = foo(true); // rust-analyzer error: top-level or-patterns are not allowed in `let` bindings

    if let Ok(x) | Err(x) = foo(true) { // rust-analyzer warn: irrefutable `if let` pattern
        println!("Working!");
    }
}
Run Code Online (Sandbox Code Playgroud)

或者这是一个 Rust 分析器错误?我尝试用谷歌搜索但找不到任何东西。

rust rust-analyzer

2
推荐指数
1
解决办法
327
查看次数

Rust-Analyzer VSCode-Plugin 与 Tauri

在 VSCode 中处理 Tauri 项目时,我从rust-analyzer插件收到以下错误消息。

rust-analyzer failed to discover workspace
Run Code Online (Sandbox Code Playgroud)

我知道问题的原因是我在 VSCode 中加载了 Tauri 项目作为我的工作区,该项目的根目录中没有 a Cargo.toml,而是在 Rust 相关的子目录中src-tauri。有没有办法告诉插件它应该引用这个src-tauri子目录Cargo.tomlsrc-tauri解决方法是每次接触 Rust 代码时都要切换工作区,这很不方便。

rust rust-cargo visual-studio-code rust-analyzer tauri

1
推荐指数
1
解决办法
1005
查看次数

我有一个“use”不起作用,即使它在我的 src 中

包含所有内容的目录称为p,位于p

.git
.gitignore
Cargo.lock
Cargo.toml
todo.md
src
target
Run Code Online (Sandbox Code Playgroud)

src

action_functions.rs
execute_action_functions.rs
lib.rs
main.rs
network.r
Run Code Online (Sandbox Code Playgroud)

network.rs

pub mod network{
        use rand::Rng    //to generate random numbers
    //use crate::action_functions::{/*insert all the action functions */};
    use rand_distr::{Normal, Distribution}; //to generate different dist. of random numbers
    use serde::{Serialize, Deserialize};    //to save/load my neural network
    use std::fs::File;
    use std::io::{BufReader, BufWriter};
    use chrono::Utc;            //for timestamp
    use std::path::Path;        //for help in representing file paths

Run Code Online (Sandbox Code Playgroud)

然后我有一堆 pub 结构,然后我有impl NeuralNetwork { …

rust rust-crates rust-cargo rust-analyzer

1
推荐指数
1
解决办法
124
查看次数

RUST:有没有更优雅的方式来导入 mod?

这是我的项目结构:

\n
.\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 src\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 main.rs\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 sub_folder\n    \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 mod.rs\n    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 sub_mod.rs\n
Run Code Online (Sandbox Code Playgroud)\n

在 中sub_mod.rs,如果我像这样导入,则货物不会警告我sub_folder/

\n
.\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 src\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 main.rs\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 sub_folder\n    \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 mod.rs\n    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 sub_mod.rs\n
Run Code Online (Sandbox Code Playgroud)\n

但我做不到

\n
#[path = "./sub_folder/mod.rs"]\nmod sub_folder;\n
Run Code Online (Sandbox Code Playgroud)\n

但它main.rs有效!

\n

有没有更温和的方式sub_mod.rs导入sub_folder/

\n

rust rust-cargo rust-analyzer

0
推荐指数
1
解决办法
1263
查看次数