Skip to content

feat(project-model): provide flag for no deps #19519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions crates/project-model/src/cargo_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down Expand Up @@ -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>)> {
Expand All @@ -316,8 +320,8 @@ impl CargoWorkspace {
current_dir,
config,
sysroot,
no_deps,
locked,
false,
progress,
);
if let Ok((_, Some(ref e))) = res {
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions crates/project-model/src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
&|_| (),
Expand Down
4 changes: 4 additions & 0 deletions crates/project-model/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ impl ProjectWorkspace {
sysroot,
sysroot_src,
target,
no_deps,
..
} = config;
let mut sysroot = match (sysroot, sysroot_src) {
Expand Down Expand Up @@ -301,6 +302,7 @@ impl ProjectWorkspace {
extra_env: extra_env.clone(),
},
&sysroot,
*no_deps,
false,
&|_| (),
) {
Expand Down Expand Up @@ -343,6 +345,7 @@ impl ProjectWorkspace {
extra_env: extra_env.clone(),
},
&sysroot,
*no_deps,
false,
&|_| (),
)
Expand Down Expand Up @@ -511,6 +514,7 @@ impl ProjectWorkspace {
extra_env: config.extra_env.clone(),
},
&sysroot,
config.no_deps,
false,
&|_| (),
)
Expand Down
4 changes: 4 additions & 0 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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".
///
Expand Down Expand Up @@ -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),
}
}

Expand Down
6 changes: 6 additions & 0 deletions docs/book/src/configuration_generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,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": {
Expand Down