我们在使用 Cargo 时很熟悉以下错误。
[ERROR rust_analyzer::lsp_utils] rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /Users/calvin/tiflash/raft-engine/Cargo.toml, Some(Version { major: 1, minor: 64, patch: 0, pre: Prerelease("nightly") }): Failed to run `"cargo" "metadata" "--format-version" "1" "--manifest-path" "/Users/calvin/tiflash/raft-engine/Cargo.toml" "--filter-platform" "x86_64-apple-darwin"`: `cargo metadata` exited with an error: Updating git repository `https://github.com/pingcap/rust-protobuf`
Updating git repository `https://github.com/tikv/raft-rs`
error: failed to load source for dependency `raft-proto`
Caused by:
Unable to update https://github.com/tikv/raft-rs?branch=master
Caused by:
failed to fetch into: /Users/calvin/.cargo/git/db/raft-rs-42b8049ef2e3af07
Caused by:
failed to authenticate when downloading repository: [email protected]:tikv/raft-rs
* attempted ssh-agent authentication, but no usernames succeeded: `git`
if the git CLI succeeds then `net.git-fetch-with-cli` may help here
https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
Caused by:
no authentication available
使用以下命令即可解决问题
eval `ssh-agent -s`
ssh-add
但是,我们如何在使用 vscode 时做到这一点呢?一种方法是使用命令行启动 vscode,但这不是一个非常简洁的解决方案。
我想知道 vscode 或 rust-analyzer 插件中是否有一些可以提供帮助的配置。
我发现修改
~/.cargo/config
可以帮助:
[net]
git-fetch-with-cli = true