Skip to content

Commit f19479a

Browse files
committed
Auto merge of #15633 - emilio:scip-cargo-config, r=lnicola
scip: Allow customizing cargo config. Re-use the LSP config json for simplicity.
2 parents b3f4574 + 791e6c8 commit f19479a

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

crates/rust-analyzer/src/cli/flags.rs

+4
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ xflags::xflags! {
131131

132132
/// The output path where the SCIP file will be written to. Defaults to `index.scip`.
133133
optional --output path: PathBuf
134+
135+
/// A path to an json configuration file that can be used to customize cargo behavior.
136+
optional --config-path config_path: PathBuf
134137
}
135138
}
136139
}
@@ -239,6 +242,7 @@ pub struct Scip {
239242
pub path: PathBuf,
240243

241244
pub output: Option<PathBuf>,
245+
pub config_path: Option<PathBuf>,
242246
}
243247

244248
impl RustAnalyzer {

crates/rust-analyzer/src/cli/scip.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use ide::{
1212
};
1313
use ide_db::LineIndexDatabase;
1414
use load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice};
15-
use project_model::{CargoConfig, RustLibSource};
1615
use scip::types as scip_types;
1716

1817
use crate::{
@@ -24,8 +23,6 @@ impl flags::Scip {
2423
pub fn run(self) -> anyhow::Result<()> {
2524
eprintln!("Generating SCIP start...");
2625
let now = Instant::now();
27-
let mut cargo_config = CargoConfig::default();
28-
cargo_config.sysroot = Some(RustLibSource::Discover);
2926

3027
let no_progress = &|s| (eprintln!("rust-analyzer: Loading {s}"));
3128
let load_cargo_config = LoadCargoConfig {
@@ -34,6 +31,20 @@ impl flags::Scip {
3431
prefill_caches: true,
3532
};
3633
let root = vfs::AbsPathBuf::assert(std::env::current_dir()?.join(&self.path)).normalize();
34+
35+
let mut config = crate::config::Config::new(
36+
root.clone(),
37+
lsp_types::ClientCapabilities::default(),
38+
/* workspace_roots = */ vec![],
39+
/* is_visual_studio_code = */ false,
40+
);
41+
42+
if let Some(p) = self.config_path {
43+
let mut file = std::io::BufReader::new(std::fs::File::open(p)?);
44+
let json = serde_json::from_reader(&mut file)?;
45+
config.update(json)?;
46+
}
47+
let cargo_config = config.cargo();
3748
let (host, vfs, _) = load_workspace_at(
3849
root.as_path().as_ref(),
3950
&cargo_config,

crates/rust-analyzer/src/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,8 @@ impl fmt::Display for ConfigError {
766766
}
767767
}
768768

769+
impl std::error::Error for ConfigError {}
770+
769771
impl Config {
770772
pub fn new(
771773
root_path: AbsPathBuf,

0 commit comments

Comments
 (0)