Allow automatically detect the rustc-src directory (fixes #3517).

If the configured rustcSource is set to "discover", try to automatically
detect a source from the sysroot rustc directory.
This commit is contained in:
Benjamin Bouvier
2021-02-11 17:34:56 +01:00
parent 2967e783ac
commit 4a6e602c94
7 changed files with 67 additions and 20 deletions

View File

@@ -18,7 +18,7 @@ use ide_db::helpers::{
};
use itertools::Itertools;
use lsp_types::{ClientCapabilities, MarkupKind};
use project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest};
use project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest, RustcSource};
use rustc_hash::FxHashSet;
use serde::{de::DeserializeOwned, Deserialize};
use vfs::AbsPathBuf;
@@ -177,8 +177,9 @@ config_data! {
/// tests or binaries.\nFor example, it may be `--release`.
runnables_cargoExtraArgs: Vec<String> = "[]",
/// Path to the rust compiler sources, for usage in rustc_private projects.
rustcSource : Option<PathBuf> = "null",
/// Path to the rust compiler sources, for usage in rustc_private projects, or "discover"
/// to try to automatically find it.
rustcSource : Option<String> = "null",
/// Additional arguments to `rustfmt`.
rustfmt_extraArgs: Vec<String> = "[]",
@@ -473,7 +474,13 @@ impl Config {
self.data.cargo_loadOutDirsFromCheck
}
pub fn cargo(&self) -> CargoConfig {
let rustc_source = self.data.rustcSource.as_ref().map(|it| self.root_path.join(&it));
let rustc_source = self.data.rustcSource.as_ref().map(|rustc_src| {
if rustc_src == "discover" {
RustcSource::Discover
} else {
RustcSource::Path(self.root_path.join(rustc_src))
}
});
CargoConfig {
no_default_features: self.data.cargo_noDefaultFeatures,