mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Auto merge of #15633 - emilio:scip-cargo-config, r=lnicola
scip: Allow customizing cargo config. Re-use the LSP config json for simplicity.
This commit is contained in:
commit
f19479a2ad
@ -131,6 +131,9 @@ xflags::xflags! {
|
|||||||
|
|
||||||
/// The output path where the SCIP file will be written to. Defaults to `index.scip`.
|
/// The output path where the SCIP file will be written to. Defaults to `index.scip`.
|
||||||
optional --output path: PathBuf
|
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 path: PathBuf,
|
||||||
|
|
||||||
pub output: Option<PathBuf>,
|
pub output: Option<PathBuf>,
|
||||||
|
pub config_path: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RustAnalyzer {
|
impl RustAnalyzer {
|
||||||
|
@ -12,7 +12,6 @@ use ide::{
|
|||||||
};
|
};
|
||||||
use ide_db::LineIndexDatabase;
|
use ide_db::LineIndexDatabase;
|
||||||
use load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice};
|
use load_cargo::{load_workspace_at, LoadCargoConfig, ProcMacroServerChoice};
|
||||||
use project_model::{CargoConfig, RustLibSource};
|
|
||||||
use scip::types as scip_types;
|
use scip::types as scip_types;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -24,8 +23,6 @@ impl flags::Scip {
|
|||||||
pub fn run(self) -> anyhow::Result<()> {
|
pub fn run(self) -> anyhow::Result<()> {
|
||||||
eprintln!("Generating SCIP start...");
|
eprintln!("Generating SCIP start...");
|
||||||
let now = Instant::now();
|
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 no_progress = &|s| (eprintln!("rust-analyzer: Loading {s}"));
|
||||||
let load_cargo_config = LoadCargoConfig {
|
let load_cargo_config = LoadCargoConfig {
|
||||||
@ -34,6 +31,20 @@ impl flags::Scip {
|
|||||||
prefill_caches: true,
|
prefill_caches: true,
|
||||||
};
|
};
|
||||||
let root = vfs::AbsPathBuf::assert(std::env::current_dir()?.join(&self.path)).normalize();
|
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(
|
let (host, vfs, _) = load_workspace_at(
|
||||||
root.as_path().as_ref(),
|
root.as_path().as_ref(),
|
||||||
&cargo_config,
|
&cargo_config,
|
||||||
|
@ -766,6 +766,8 @@ impl fmt::Display for ConfigError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for ConfigError {}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
root_path: AbsPathBuf,
|
root_path: AbsPathBuf,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user