rust-analyzer.linkedProjects doesn't work with relative path, ${workspaceFolder}. Is there any workaround?

4.1k Views Asked by At
  • I have a repository that has a Cargo.toml in sub_dir/Cargo.toml (Cargo.toml is not in repository root directory)
  • I'm using the repository from some of my computers. So I need to set up rust-analyzer.linkedProjects by each environment...

I want to avoid the configuration by machine. Do you know anything workaround?

2

There are 2 best solutions below

1
On BEST ANSWER

to .vscode/settings.json, should add the path to Cargo.toml, like this.

// correct
"rust-analyzer.linkedProjects": [
  "relateive/path/to/the/project/directory/Cargo.toml",
]

// incorrect
"rust-analyzer.linkedProjects": [
  "relateive/path/to/the/project/directory",
]
1
On

In .vscode/settings.json set the "rust-analyzer.linkedProjects" point to your Cargo.toml using an absolute path. That's the only way I got it to work eventhough all the resources online tend to tell you to use a relative path.

"rust-analyzer.linkedProjects": [
  "absolute/path/to/the/project/Cargo.toml"
],