Skip to content

Commit

Permalink
Disable eqwalizer for OTP < 26 (#48)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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
  • Loading branch information
alanz authored and facebook-github-bot committed Aug 22, 2024
1 parent 61700b1 commit 7dbc884
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/base_db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/base_db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ pub trait SourceDatabase: FileLoader + salsa::Database {
#[salsa::input]
fn project_data(&self, id: ProjectId) -> Arc<ProjectData>;

#[salsa::input]
fn otp_version(&self) -> Option<String>;

/// 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
Expand Down
9 changes: 9 additions & 0 deletions crates/ide_db/src/eqwalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions crates/project_model/src/otp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
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<ProjectAppData>) {
let apps = Self::discover_otp_apps(&path);
Expand Down

0 comments on commit 7dbc884

Please sign in to comment.