We are quite familiar with the following errors when using 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: git@github.com: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
By using the following commands, problem can be solved
eval `ssh-agent -s`
ssh-add
However, how can we do this while using vscode? One way is to use command line to start vscode, but this is a not very neat solution.
I wonder if there are some configs in vscode or the rust-analyzer plugin that can help.
Modify (or create a new file if it doesn't exist) ~/.cargo/config.toml
with the following config:
[net]
git-fetch-with-cli = true