Skip to content

Commit

Permalink
EqwalizerConfig as Salsa input
Browse files Browse the repository at this point in the history
Summary: Move EqwalizerConfig to the database as a salsa input, following discussion on D57670816.

Reviewed By: alanz

Differential Revision: D57971184

fbshipit-source-id: 1bd717c80488c54b20a1faf9ab445081fee724ff
  • Loading branch information
VLanvin authored and facebook-github-bot committed May 31, 2024
1 parent f779dce commit e980308
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
4 changes: 3 additions & 1 deletion crates/elp/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions crates/elp/src/build/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,11 @@ fn load_database(
eqwalizer_mode: elp_eqwalizer::Mode,
) -> Result<AnalysisHost> {
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 {
Expand Down
7 changes: 4 additions & 3 deletions crates/eqwalizer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ pub struct Eqwalizer {
cmd: OsString,
args: Vec<OsString>,
pub mode: Mode,
pub config: EqwalizerConfig,
// Used only for the Drop implementation
_file: Option<Arc<TempPath>>,
}
Expand Down Expand Up @@ -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<EqwalizerConfig>;

fn module_diagnostics(
&self,
project_id: ProjectId,
Expand Down Expand Up @@ -241,7 +243,6 @@ impl Eqwalizer {
cmd,
args,
mode: Mode::Server,
config: EqwalizerConfig::default(),
_file: temp_file.map(Arc::new),
}
}
Expand All @@ -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());
Expand Down
20 changes: 15 additions & 5 deletions crates/ide_db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -112,14 +113,27 @@ pub trait EqwalizerProgressReporter: Send + Sync + RefUnwindSafe {
hir::db::InternDatabaseStorage,
hir::db::DefDatabaseStorage
)]
#[derive(Default)]

pub struct RootDatabase {
storage: salsa::Storage<Self>,
erlang_services: Arc<AssertUnwindSafe<RwLock<FxHashMap<ProjectId, Connection>>>>,
eqwalizer: Eqwalizer,
eqwalizer_progress_reporter: EqwalizerProgressReporterBox,
ipc_handles: Arc<AssertUnwindSafe<RwLock<FxHashMap<String, Arc<Mutex<IpcHandle>>>>>>,
}
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<dyn SourceDatabase> for RootDatabase {
fn upcast(&self) -> &(dyn SourceDatabase + 'static) {
Expand Down Expand Up @@ -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<Includes> {
let source_file = self.parse(file_id).tree();
// Context for T171541590
Expand Down

0 comments on commit e980308

Please sign in to comment.