From 7dbc884ac97a95d6aecb75e387dc39c5fd533735 Mon Sep 17 00:00:00 2001 From: Alan Zimmerman Date: Thu, 22 Aug 2024 07:24:57 -0700 Subject: [PATCH] Disable eqwalizer for OTP < 26 (#48) Summary: Pull Request resolved: https://github.com/WhatsApp/erlang-language-platform/pull/48 OSS users want to use ELP with OTP < 26. But eqwalizer does not support this. So disable eqwalizer diagnostics in this case. Differential Revision: D61660600 --- crates/base_db/src/input.rs | 3 +++ crates/base_db/src/lib.rs | 3 +++ crates/ide_db/src/eqwalizer.rs | 9 +++++++++ crates/project_model/src/otp.rs | 22 ++++++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs index dc703bef8..a67213fd0 100644 --- a/crates/base_db/src/input.rs +++ b/crates/base_db/src/input.rs @@ -12,6 +12,7 @@ use std::hash::Hash; use std::path::Path; use std::sync::Arc; +use elp_project_model::otp::Otp; use elp_project_model::AppName; use elp_project_model::AppType; use elp_project_model::EqwalizerConfig; @@ -194,6 +195,8 @@ impl AppStructure { db.set_project_data(project_id, Arc::new(project_data)); } db.set_catch_all_source_root(self.catch_all_source_root); + + db.set_otp_version(Otp::otp_version().ok()); } } diff --git a/crates/base_db/src/lib.rs b/crates/base_db/src/lib.rs index 6dbdefece..ffa25b732 100644 --- a/crates/base_db/src/lib.rs +++ b/crates/base_db/src/lib.rs @@ -148,6 +148,9 @@ pub trait SourceDatabase: FileLoader + salsa::Database { #[salsa::input] fn project_data(&self, id: ProjectId) -> Arc; + #[salsa::input] + fn otp_version(&self) -> Option; + /// A revision number that is bumped when the file state changes. /// Crucially, we update it in server mode when the unsaved file /// contents are changed in VFS, but also when we receive a diff --git a/crates/ide_db/src/eqwalizer.rs b/crates/ide_db/src/eqwalizer.rs index d20fe026f..37968408c 100644 --- a/crates/ide_db/src/eqwalizer.rs +++ b/crates/ide_db/src/eqwalizer.rs @@ -154,6 +154,9 @@ fn is_eqwalizer_enabled( file_id: FileId, include_generated: bool, ) -> bool { + if !otp_supported_by_eqwalizer(db) { + return false; + } if !include_generated && db.is_generated(file_id) { return false; } @@ -178,6 +181,12 @@ fn is_eqwalizer_enabled( opt_in && !ignored } +fn otp_supported_by_eqwalizer(db: &dyn EqwalizerDatabase) -> bool { + db.otp_version() + .and_then(|v| Some(v.as_str() > "25")) + .unwrap_or(true) +} + fn has_eqwalizer_app_marker(db: &dyn EqwalizerDatabase, source_root_id: SourceRootId) -> bool { if let Some(app_data) = db.app_data(source_root_id) { let source_root = db.source_root(source_root_id); diff --git a/crates/project_model/src/otp.rs b/crates/project_model/src/otp.rs index 3388a4428..ad1bb0b24 100644 --- a/crates/project_model/src/otp.rs +++ b/crates/project_model/src/otp.rs @@ -55,6 +55,28 @@ impl Otp { let result = fs::canonicalize(result)?; Ok(Utf8PathBuf::from_path_buf(result).expect("Could not create Utf8PathBuf")) } + pub fn otp_version() -> Result { + let _timer = timeit!("otp_version"); + let erl = ERL.read().unwrap(); + let output = Command::new(&*erl) + .arg("-noshell") + .arg("-eval") + .arg("io:format('~s', [erlang:system_info(otp_release)])") + .arg("-s") + .arg("erlang") + .arg("halt") + .output()?; + + if !output.status.success() { + bail!( + "Failed to get OTP version, error code: {:?}, stderr: {:?}", + output.status.code(), + String::from_utf8(output.stderr) + ); + } + let val = String::from_utf8(output.stdout)?; + Ok(val) + } pub fn discover(path: Utf8PathBuf) -> (Otp, Vec) { let apps = Self::discover_otp_apps(&path);