Skip to content

Commit 55c8cde

Browse files
authored
Merge pull request #19519 from snprajwal/project-control-no-deps
feat(project-model): provide flag for no deps
2 parents 16a7250 + 865681d commit 55c8cde

File tree

6 files changed

+31
-2
lines changed

6 files changed

+31
-2
lines changed

Diff for: crates/project-model/src/cargo_workspace.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ pub struct CargoConfig {
108108
pub invocation_strategy: InvocationStrategy,
109109
/// Optional path to use instead of `target` when building
110110
pub target_dir: Option<Utf8PathBuf>,
111+
/// Gate `#[test]` behind `#[cfg(test)]`
111112
pub set_test: bool,
113+
/// Load the project without any dependencies
114+
pub no_deps: bool,
112115
}
113116

114117
pub type Package = Idx<PackageData>;
@@ -308,6 +311,7 @@ impl CargoWorkspace {
308311
current_dir: &AbsPath,
309312
config: &CargoMetadataConfig,
310313
sysroot: &Sysroot,
314+
no_deps: bool,
311315
locked: bool,
312316
progress: &dyn Fn(String),
313317
) -> anyhow::Result<(cargo_metadata::Metadata, Option<anyhow::Error>)> {
@@ -316,8 +320,8 @@ impl CargoWorkspace {
316320
current_dir,
317321
config,
318322
sysroot,
323+
no_deps,
319324
locked,
320-
false,
321325
progress,
322326
);
323327
if let Ok((_, Some(ref e))) = res {
@@ -335,8 +339,8 @@ impl CargoWorkspace {
335339
current_dir: &AbsPath,
336340
config: &CargoMetadataConfig,
337341
sysroot: &Sysroot,
338-
locked: bool,
339342
no_deps: bool,
343+
locked: bool,
340344
progress: &dyn Fn(String),
341345
) -> anyhow::Result<(cargo_metadata::Metadata, Option<anyhow::Error>)> {
342346
let cargo = sysroot.tool(Tool::Cargo, current_dir);

Diff for: crates/project-model/src/sysroot.rs

+1
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ impl Sysroot {
300300
rust_lib_src_dir,
301301
&cargo_config,
302302
self,
303+
false,
303304
// Make sure we never attempt to write to the sysroot
304305
true,
305306
&|_| (),

Diff for: crates/project-model/src/workspace.rs

+4
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ impl ProjectWorkspace {
220220
sysroot,
221221
sysroot_src,
222222
target,
223+
no_deps,
223224
..
224225
} = config;
225226
let mut sysroot = match (sysroot, sysroot_src) {
@@ -301,6 +302,7 @@ impl ProjectWorkspace {
301302
extra_env: extra_env.clone(),
302303
},
303304
&sysroot,
305+
*no_deps,
304306
false,
305307
&|_| (),
306308
) {
@@ -343,6 +345,7 @@ impl ProjectWorkspace {
343345
extra_env: extra_env.clone(),
344346
},
345347
&sysroot,
348+
*no_deps,
346349
false,
347350
&|_| (),
348351
)
@@ -511,6 +514,7 @@ impl ProjectWorkspace {
511514
extra_env: config.extra_env.clone(),
512515
},
513516
&sysroot,
517+
config.no_deps,
514518
false,
515519
&|_| (),
516520
)

Diff for: crates/rust-analyzer/src/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,9 @@ config_data! {
609609
cargo_features: CargoFeaturesDef = CargoFeaturesDef::Selected(vec![]),
610610
/// Whether to pass `--no-default-features` to cargo.
611611
cargo_noDefaultFeatures: bool = false,
612+
/// Whether to skip fetching dependencies. If set to "true", the analysis is performed
613+
/// entirely offline, and Cargo metadata for dependencies is not fetched.
614+
cargo_noDeps: bool = false,
612615
/// Relative path to the sysroot, or "discover" to try to automatically find it via
613616
/// "rustc --print sysroot".
614617
///
@@ -2027,6 +2030,7 @@ impl Config {
20272030
extra_env: self.cargo_extraEnv(source_root).clone(),
20282031
target_dir: self.target_dir_from_config(source_root),
20292032
set_test: *self.cfg_setTest(source_root),
2033+
no_deps: *self.cargo_noDeps(source_root),
20302034
}
20312035
}
20322036

Diff for: docs/book/src/configuration_generated.md

+6
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ Set this to `"all"` to pass `--all-features` to cargo.
130130
Whether to pass `--no-default-features` to cargo.
131131

132132

133+
**rust-analyzer.cargo.noDeps** (default: false)
134+
135+
Whether to skip fetching dependencies. If set to "true", the analysis is performed
136+
entirely offline, and Cargo metadata for dependencies is not fetched.
137+
138+
133139
**rust-analyzer.cargo.sysroot** (default: "discover")
134140

135141
Relative path to the sysroot, or "discover" to try to automatically find it via

Diff for: editors/code/package.json

+10
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,16 @@
891891
}
892892
}
893893
},
894+
{
895+
"title": "cargo",
896+
"properties": {
897+
"rust-analyzer.cargo.noDeps": {
898+
"markdownDescription": "Whether to skip fetching dependencies. If set to \"true\", the analysis is performed\nentirely offline, and Cargo metadata for dependencies is not fetched.",
899+
"default": false,
900+
"type": "boolean"
901+
}
902+
}
903+
},
894904
{
895905
"title": "cargo",
896906
"properties": {

0 commit comments

Comments
 (0)