Skip to content

Commit

Permalink
Auto merge of #15633 - emilio:scip-cargo-config, r=lnicola
Browse files Browse the repository at this point in the history
scip: Allow customizing cargo config.

Re-use the LSP config json for simplicity.
  • Loading branch information
bors committed Sep 28, 2023
2 parents b3f4574 + 791e6c8 commit f19479a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions crates/rust-analyzer/src/cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down Expand Up @@ -239,6 +242,7 @@ pub struct Scip {
pub path: PathBuf,

pub output: Option<PathBuf>,
pub config_path: Option<PathBuf>,
}

impl RustAnalyzer {
Expand Down
17 changes: 14 additions & 3 deletions crates/rust-analyzer/src/cli/scip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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 {
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,8 @@ impl fmt::Display for ConfigError {
}
}

impl std::error::Error for ConfigError {}

impl Config {
pub fn new(
root_path: AbsPathBuf,
Expand Down

0 comments on commit f19479a

Please sign in to comment.