Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/project-model/src/cargo_workspace.rs8
-rw-r--r--crates/project-model/src/sysroot.rs1
-rw-r--r--crates/project-model/src/workspace.rs4
-rw-r--r--crates/rust-analyzer/src/config.rs4
-rw-r--r--docs/book/src/configuration_generated.md6
-rw-r--r--editors/code/package.json10
6 files changed, 31 insertions, 2 deletions
diff --git a/crates/project-model/src/cargo_workspace.rs b/crates/project-model/src/cargo_workspace.rs
index 971193229a..d304c9762c 100644
--- a/crates/project-model/src/cargo_workspace.rs
+++ b/crates/project-model/src/cargo_workspace.rs
@@ -108,7 +108,10 @@ pub struct CargoConfig {
pub invocation_strategy: InvocationStrategy,
/// Optional path to use instead of `target` when building
pub target_dir: Option<Utf8PathBuf>,
+ /// Gate `#[test]` behind `#[cfg(test)]`
pub set_test: bool,
+ /// Load the project without any dependencies
+ pub no_deps: bool,
}
pub type Package = Idx<PackageData>;
@@ -308,6 +311,7 @@ impl CargoWorkspace {
current_dir: &AbsPath,
config: &CargoMetadataConfig,
sysroot: &Sysroot,
+ no_deps: bool,
locked: bool,
progress: &dyn Fn(String),
) -> anyhow::Result<(cargo_metadata::Metadata, Option<anyhow::Error>)> {
@@ -316,8 +320,8 @@ impl CargoWorkspace {
current_dir,
config,
sysroot,
+ no_deps,
locked,
- false,
progress,
);
if let Ok((_, Some(ref e))) = res {
@@ -335,8 +339,8 @@ impl CargoWorkspace {
current_dir: &AbsPath,
config: &CargoMetadataConfig,
sysroot: &Sysroot,
- locked: bool,
no_deps: bool,
+ locked: bool,
progress: &dyn Fn(String),
) -> anyhow::Result<(cargo_metadata::Metadata, Option<anyhow::Error>)> {
let cargo = sysroot.tool(Tool::Cargo, current_dir);
diff --git a/crates/project-model/src/sysroot.rs b/crates/project-model/src/sysroot.rs
index 7e8db8d39d..6ed030a4c3 100644
--- a/crates/project-model/src/sysroot.rs
+++ b/crates/project-model/src/sysroot.rs
@@ -300,6 +300,7 @@ impl Sysroot {
rust_lib_src_dir,
&cargo_config,
self,
+ false,
// Make sure we never attempt to write to the sysroot
true,
&|_| (),
diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs
index 857ea84d9b..a0fb4a7d0f 100644
--- a/crates/project-model/src/workspace.rs
+++ b/crates/project-model/src/workspace.rs
@@ -220,6 +220,7 @@ impl ProjectWorkspace {
sysroot,
sysroot_src,
target,
+ no_deps,
..
} = config;
let mut sysroot = match (sysroot, sysroot_src) {
@@ -301,6 +302,7 @@ impl ProjectWorkspace {
extra_env: extra_env.clone(),
},
&sysroot,
+ *no_deps,
false,
&|_| (),
) {
@@ -343,6 +345,7 @@ impl ProjectWorkspace {
extra_env: extra_env.clone(),
},
&sysroot,
+ *no_deps,
false,
&|_| (),
)
@@ -511,6 +514,7 @@ impl ProjectWorkspace {
extra_env: config.extra_env.clone(),
},
&sysroot,
+ config.no_deps,
false,
&|_| (),
)
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 351b2a6c8b..aceacff985 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -609,6 +609,9 @@ config_data! {
cargo_features: CargoFeaturesDef = CargoFeaturesDef::Selected(vec![]),
/// Whether to pass `--no-default-features` to cargo.
cargo_noDefaultFeatures: bool = false,
+ /// Whether to skip fetching dependencies. If set to "true", the analysis is performed
+ /// entirely offline, and Cargo metadata for dependencies is not fetched.
+ cargo_noDeps: bool = false,
/// Relative path to the sysroot, or "discover" to try to automatically find it via
/// "rustc --print sysroot".
///
@@ -2027,6 +2030,7 @@ impl Config {
extra_env: self.cargo_extraEnv(source_root).clone(),
target_dir: self.target_dir_from_config(source_root),
set_test: *self.cfg_setTest(source_root),
+ no_deps: *self.cargo_noDeps(source_root),
}
}
diff --git a/docs/book/src/configuration_generated.md b/docs/book/src/configuration_generated.md
index 0a612d20b9..860d8240fd 100644
--- a/docs/book/src/configuration_generated.md
+++ b/docs/book/src/configuration_generated.md
@@ -130,6 +130,12 @@ Set this to `"all"` to pass `--all-features` to cargo.
Whether to pass `--no-default-features` to cargo.
+**rust-analyzer.cargo.noDeps** (default: false)
+
+ Whether to skip fetching dependencies. If set to "true", the analysis is performed
+entirely offline, and Cargo metadata for dependencies is not fetched.
+
+
**rust-analyzer.cargo.sysroot** (default: "discover")
Relative path to the sysroot, or "discover" to try to automatically find it via
diff --git a/editors/code/package.json b/editors/code/package.json
index 55477b7115..a04886270b 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -894,6 +894,16 @@
{
"title": "cargo",
"properties": {
+ "rust-analyzer.cargo.noDeps": {
+ "markdownDescription": "Whether to skip fetching dependencies. If set to \"true\", the analysis is performed\nentirely offline, and Cargo metadata for dependencies is not fetched.",
+ "default": false,
+ "type": "boolean"
+ }
+ }
+ },
+ {
+ "title": "cargo",
+ "properties": {
"rust-analyzer.cargo.sysroot": {
"markdownDescription": "Relative path to the sysroot, or \"discover\" to try to automatically find it via\n\"rustc --print sysroot\".\n\nUnsetting this disables sysroot loading.\n\nThis option does not take effect until rust-analyzer is restarted.",
"default": "discover",