diff options
| author | bors <bors@rust-lang.org> | 2023-09-28 15:25:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-28 15:25:15 +0000 |
| commit | f19479a2ad238ad861cfe8d57e63beeccb56169e (patch) | |
| tree | df51a7f391097ef9be28a814db2ff30032f090f2 | |
| parent | b3f45745ea0502e664711f130f9d01f87b99fd27 (diff) | |
| parent | 791e6c8b1b48e1e9e051cc05443ff65f8ecc0f92 (diff) | |
| download | rust-f19479a2ad238ad861cfe8d57e63beeccb56169e.tar.gz rust-f19479a2ad238ad861cfe8d57e63beeccb56169e.zip | |
Auto merge of #15633 - emilio:scip-cargo-config, r=lnicola
scip: Allow customizing cargo config. Re-use the LSP config json for simplicity.
| -rw-r--r-- | crates/rust-analyzer/src/cli/flags.rs | 4 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/cli/scip.rs | 17 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/config.rs | 2 |
3 files changed, 20 insertions, 3 deletions
diff --git a/crates/rust-analyzer/src/cli/flags.rs b/crates/rust-analyzer/src/cli/flags.rs index 419440b6df7..fe5022f8606 100644 --- a/crates/rust-analyzer/src/cli/flags.rs +++ b/crates/rust-analyzer/src/cli/flags.rs @@ -131,6 +131,9 @@ xflags::xflags! { /// The output path where the SCIP file will be written to. Defaults to `index.scip`. optional --output path: PathBuf + + /// A path to an json configuration file that can be used to customize cargo behavior. + optional --config-path config_path: PathBuf } } } @@ -239,6 +242,7 @@ pub struct Scip { pub path: PathBuf, pub output: Option<PathBuf>, + pub config_path: Option<PathBuf>, } impl RustAnalyzer { diff --git a/crates/rust-analyzer/src/cli/scip.rs b/crates/rust-analyzer/src/cli/scip.rs index 875b724bd89..b058e6d153f 100644 --- a/crates/rust-analyzer/src/cli/scip.rs +++ b/crates/rust-analyzer/src/cli/scip.rs @@ -12,7 +12,6 @@ use ide::{ }; use ide_db::LineIndexDatabase; use load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice}; -use project_model::{CargoConfig, RustLibSource}; use scip::types as scip_types; use crate::{ @@ -24,8 +23,6 @@ impl flags::Scip { pub fn run(self) -> anyhow::Result<()> { eprintln!("Generating SCIP start..."); let now = Instant::now(); - let mut cargo_config = CargoConfig::default(); - cargo_config.sysroot = Some(RustLibSource::Discover); let no_progress = &|s| (eprintln!("rust-analyzer: Loading {s}")); let load_cargo_config = LoadCargoConfig { @@ -34,6 +31,20 @@ impl flags::Scip { prefill_caches: true, }; let root = vfs::AbsPathBuf::assert(std::env::current_dir()?.join(&self.path)).normalize(); + + let mut config = crate::config::Config::new( + root.clone(), + lsp_types::ClientCapabilities::default(), + /* workspace_roots = */ vec![], + /* is_visual_studio_code = */ false, + ); + + if let Some(p) = self.config_path { + let mut file = std::io::BufReader::new(std::fs::File::open(p)?); + let json = serde_json::from_reader(&mut file)?; + config.update(json)?; + } + let cargo_config = config.cargo(); let (host, vfs, _) = load_workspace_at( root.as_path().as_ref(), &cargo_config, diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index cc7f2da532c..8e780baa36d 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -766,6 +766,8 @@ impl fmt::Display for ConfigError { } } +impl std::error::Error for ConfigError {} + impl Config { pub fn new( root_path: AbsPathBuf, |
