vscode 有多个货运项目时不起作用?

问题描述 投票:0回答:2

我正在学习使用rust,我正在使用vscode。 我的工作区中有两个 Cargo 项目,为什么 rust-analyzer 只在第一个项目中有错误消息,而在第二个项目中没有。 enter image description here

enter image description here

需要什么设置吗?

visual-studio-code rust rust-cargo rust-analyzer
2个回答
5
投票

您需要创建工作区:

  • 在根项目中创建
    Cargo.toml
  • 添加此代码:
[workspace]
members = [
    "./<your-cargo-project1>",
    "./<your-cargo-project2>",


]

0
投票

我的解决方案是将所有

Cargo.toml
的相对路径添加到工作区中的
rust-analyzer.linkedProjects
设置(
.vscode/settings.json
Ctrl+Shift+P > Preferences: Open Workspace Settings (JSON)
)。

{
  "rust-analyzer.linkedProjects": [
    "cargo-test/Cargo.toml",
    "codecrafters-git-rust/Cargo.toml"
  ]
}

这有助于智能感知在这两个项目中发挥作用。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.