Merge pull request #19519 from snprajwal/project-control-no-deps

feat(project-model): provide flag for no deps
This commit is contained in:
Lukas Wirth 2025-04-04 16:50:27 +00:00 committed by GitHub
commit 55c8cdeafb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 31 additions and 2 deletions

View File

@ -108,7 +108,10 @@ pub struct CargoConfig {
pub invocation_strategy: InvocationStrategy, pub invocation_strategy: InvocationStrategy,
/// Optional path to use instead of `target` when building /// Optional path to use instead of `target` when building
pub target_dir: Option<Utf8PathBuf>, pub target_dir: Option<Utf8PathBuf>,
/// Gate `#[test]` behind `#[cfg(test)]`
pub set_test: bool, pub set_test: bool,
/// Load the project without any dependencies
pub no_deps: bool,
} }
pub type Package = Idx<PackageData>; pub type Package = Idx<PackageData>;
@ -308,6 +311,7 @@ impl CargoWorkspace {
current_dir: &AbsPath, current_dir: &AbsPath,
config: &CargoMetadataConfig, config: &CargoMetadataConfig,
sysroot: &Sysroot, sysroot: &Sysroot,
no_deps: bool,
locked: bool, locked: bool,
progress: &dyn Fn(String), progress: &dyn Fn(String),
) -> anyhow::Result<(cargo_metadata::Metadata, Option<anyhow::Error>)> { ) -> anyhow::Result<(cargo_metadata::Metadata, Option<anyhow::Error>)> {
@ -316,8 +320,8 @@ impl CargoWorkspace {
current_dir, current_dir,
config, config,
sysroot, sysroot,
no_deps,
locked, locked,
false,
progress, progress,
); );
if let Ok((_, Some(ref e))) = res { if let Ok((_, Some(ref e))) = res {
@ -335,8 +339,8 @@ impl CargoWorkspace {
current_dir: &AbsPath, current_dir: &AbsPath,
config: &CargoMetadataConfig, config: &CargoMetadataConfig,
sysroot: &Sysroot, sysroot: &Sysroot,
locked: bool,
no_deps: bool, no_deps: bool,
locked: bool,
progress: &dyn Fn(String), progress: &dyn Fn(String),
) -> anyhow::Result<(cargo_metadata::Metadata, Option<anyhow::Error>)> { ) -> anyhow::Result<(cargo_metadata::Metadata, Option<anyhow::Error>)> {
let cargo = sysroot.tool(Tool::Cargo, current_dir); let cargo = sysroot.tool(Tool::Cargo, current_dir);

View File

@ -300,6 +300,7 @@ impl Sysroot {
rust_lib_src_dir, rust_lib_src_dir,
&cargo_config, &cargo_config,
self, self,
false,
// Make sure we never attempt to write to the sysroot // Make sure we never attempt to write to the sysroot
true, true,
&|_| (), &|_| (),

View File

@ -220,6 +220,7 @@ impl ProjectWorkspace {
sysroot, sysroot,
sysroot_src, sysroot_src,
target, target,
no_deps,
.. ..
} = config; } = config;
let mut sysroot = match (sysroot, sysroot_src) { let mut sysroot = match (sysroot, sysroot_src) {
@ -301,6 +302,7 @@ impl ProjectWorkspace {
extra_env: extra_env.clone(), extra_env: extra_env.clone(),
}, },
&sysroot, &sysroot,
*no_deps,
false, false,
&|_| (), &|_| (),
) { ) {
@ -343,6 +345,7 @@ impl ProjectWorkspace {
extra_env: extra_env.clone(), extra_env: extra_env.clone(),
}, },
&sysroot, &sysroot,
*no_deps,
false, false,
&|_| (), &|_| (),
) )
@ -511,6 +514,7 @@ impl ProjectWorkspace {
extra_env: config.extra_env.clone(), extra_env: config.extra_env.clone(),
}, },
&sysroot, &sysroot,
config.no_deps,
false, false,
&|_| (), &|_| (),
) )

View File

@ -609,6 +609,9 @@ config_data! {
cargo_features: CargoFeaturesDef = CargoFeaturesDef::Selected(vec![]), cargo_features: CargoFeaturesDef = CargoFeaturesDef::Selected(vec![]),
/// Whether to pass `--no-default-features` to cargo. /// Whether to pass `--no-default-features` to cargo.
cargo_noDefaultFeatures: bool = false, 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 /// Relative path to the sysroot, or "discover" to try to automatically find it via
/// "rustc --print sysroot". /// "rustc --print sysroot".
/// ///
@ -2027,6 +2030,7 @@ impl Config {
extra_env: self.cargo_extraEnv(source_root).clone(), extra_env: self.cargo_extraEnv(source_root).clone(),
target_dir: self.target_dir_from_config(source_root), target_dir: self.target_dir_from_config(source_root),
set_test: *self.cfg_setTest(source_root), set_test: *self.cfg_setTest(source_root),
no_deps: *self.cargo_noDeps(source_root),
} }
} }

View File

@ -130,6 +130,12 @@ Set this to `"all"` to pass `--all-features` to cargo.
Whether to pass `--no-default-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") **rust-analyzer.cargo.sysroot** (default: "discover")
Relative path to the sysroot, or "discover" to try to automatically find it via Relative path to the sysroot, or "discover" to try to automatically find it via

View File

@ -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", "title": "cargo",
"properties": { "properties": {