From e98030897c626b8bc816f4f8d086e021032c1069 Mon Sep 17 00:00:00 2001 From: Victor Lanvin Date: Fri, 31 May 2024 09:02:27 -0700 Subject: [PATCH] EqwalizerConfig as Salsa input Summary: Move EqwalizerConfig to the database as a salsa input, following discussion on D57670816. Reviewed By: alanz Differential Revision: D57971184 fbshipit-source-id: 1bd717c80488c54b20a1faf9ab445081fee724ff --- crates/elp/src/bin/main.rs | 4 +++- crates/elp/src/build/load.rs | 5 ++--- crates/eqwalizer/src/lib.rs | 7 ++++--- crates/ide_db/src/lib.rs | 20 +++++++++++++++----- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/crates/elp/src/bin/main.rs b/crates/elp/src/bin/main.rs index 52737b02a3..41e926608b 100644 --- a/crates/elp/src/bin/main.rs +++ b/crates/elp/src/bin/main.rs @@ -191,6 +191,7 @@ mod tests { use std::ffi::OsString; use std::path::Path; use std::str; + use std::sync::Arc; use anyhow::Context; use bpaf::Args; @@ -199,6 +200,7 @@ mod tests { use elp::cli::Fake; use elp_eqwalizer::EqwalizerConfig; use elp_eqwalizer::EqwalizerDiagnostics; + use elp_eqwalizer::EqwalizerDiagnosticsDatabase; use elp_eqwalizer::Mode; use elp_ide::elp_ide_db::diagnostic_code::BASE_URL; use elp_ide::elp_ide_db::elp_base_db::FileId; @@ -324,7 +326,7 @@ mod tests { loaded .analysis_host .raw_database_mut() - .set_eqwalizer_config(config); + .set_eqwalizer_config(Arc::new(config)); build::compile_deps(&loaded, &mut cli) .with_context(|| format!("Failed to compile deps for project {}", project)) .unwrap(); diff --git a/crates/elp/src/build/load.rs b/crates/elp/src/build/load.rs index 82a3fb1abc..66c6060b94 100644 --- a/crates/elp/src/build/load.rs +++ b/crates/elp/src/build/load.rs @@ -140,12 +140,11 @@ fn load_database( eqwalizer_mode: elp_eqwalizer::Mode, ) -> Result { let mut analysis_host = AnalysisHost::default(); - analysis_host - .raw_database_mut() - .set_eqwalizer_mode(eqwalizer_mode); let db = analysis_host.raw_database_mut(); + db.set_eqwalizer_mode(eqwalizer_mode); + let pb = cli.simple_progress(0, "Loading applications"); for task in receiver { diff --git a/crates/eqwalizer/src/lib.rs b/crates/eqwalizer/src/lib.rs index 858f8eb1cf..77dce2aab7 100644 --- a/crates/eqwalizer/src/lib.rs +++ b/crates/eqwalizer/src/lib.rs @@ -101,7 +101,6 @@ pub struct Eqwalizer { cmd: OsString, args: Vec, pub mode: Mode, - pub config: EqwalizerConfig, // Used only for the Drop implementation _file: Option>, } @@ -170,6 +169,9 @@ pub trait DbApi { #[salsa::query_group(EqwalizerDiagnosticsDatabaseStorage)] pub trait EqwalizerDiagnosticsDatabase: ast::db::EqwalizerASTDatabase + DbApi { + #[salsa::input] + fn eqwalizer_config(&self) -> Arc; + fn module_diagnostics( &self, project_id: ProjectId, @@ -241,7 +243,6 @@ impl Eqwalizer { cmd, args, mode: Mode::Server, - config: EqwalizerConfig::default(), _file: temp_file.map(Arc::new), } } @@ -261,7 +262,7 @@ impl Eqwalizer { modules: Vec<&str>, ) -> EqwalizerDiagnostics { let mut cmd = self.cmd(); - self.config.set_cmd_env(&mut cmd); + db.eqwalizer_config().set_cmd_env(&mut cmd); cmd.arg("ipc"); cmd.args(modules); cmd.env("EQWALIZER_MODE", self.mode.to_env_var()); diff --git a/crates/ide_db/src/lib.rs b/crates/ide_db/src/lib.rs index e63b5616ac..b7df19002d 100644 --- a/crates/ide_db/src/lib.rs +++ b/crates/ide_db/src/lib.rs @@ -27,6 +27,7 @@ use elp_base_db::SourceDatabase; use elp_base_db::Upcast; use elp_eqwalizer::ipc::IpcHandle; use elp_eqwalizer::EqwalizerConfig; +use elp_eqwalizer::EqwalizerDiagnosticsDatabase; use elp_eqwalizer::Mode; use elp_syntax::AstNode; use elp_syntax::SyntaxKind; @@ -112,7 +113,7 @@ pub trait EqwalizerProgressReporter: Send + Sync + RefUnwindSafe { hir::db::InternDatabaseStorage, hir::db::DefDatabaseStorage )] -#[derive(Default)] + pub struct RootDatabase { storage: salsa::Storage, erlang_services: Arc>>>, @@ -120,6 +121,19 @@ pub struct RootDatabase { eqwalizer_progress_reporter: EqwalizerProgressReporterBox, ipc_handles: Arc>>>>>, } +impl Default for RootDatabase { + fn default() -> Self { + let mut db = RootDatabase { + storage: salsa::Storage::default(), + erlang_services: Arc::default(), + eqwalizer: Eqwalizer::default(), + eqwalizer_progress_reporter: EqwalizerProgressReporterBox::default(), + ipc_handles: Arc::default(), + }; + db.set_eqwalizer_config(Arc::new(EqwalizerConfig::default())); + db + } +} impl Upcast for RootDatabase { fn upcast(&self) -> &(dyn SourceDatabase + 'static) { @@ -224,10 +238,6 @@ impl RootDatabase { self.eqwalizer.mode = mode } - pub fn set_eqwalizer_config(&mut self, config: EqwalizerConfig) { - self.eqwalizer.config = config - } - pub fn resolved_includes(&self, file_id: FileId) -> Option { let source_file = self.parse(file_id).tree(); // Context for T171541590