Skip to content

Commit

Permalink
elp lint: automatically request erlang serivice diagnostics if needed
Browse files Browse the repository at this point in the history
Summary:
We will be moving toward tracking the sources for diagnostics, and requesting info from the required set of sources as needed.

Rather than tramp the `--request-erlc-diagnostics` through all the CI machinery, determine from the enabled diagnostics if it is needed, as a start toward that.

Reviewed By: jcpetruzza

Differential Revision: D59802484

fbshipit-source-id: 1261f6a54669372404e273b380ecc0e697ed30cd
  • Loading branch information
alanz authored and facebook-github-bot committed Jul 16, 2024
1 parent aae051d commit 4d95be1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/elp/src/bin/lint_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn do_parse_one(
let mut diagnostics = DiagnosticCollection::default();
let native = db.native_diagnostics(config, file_id)?;
diagnostics.set_native(file_id, native);
if args.include_erlc_diagnostics {
if args.include_erlc_diagnostics || config.request_erlang_service_diagnostics {
let erlang_service =
db.erlang_service_diagnostics(file_id, config, RemoveElpReported::Yes)?;
for (file_id, diags) in erlang_service {
Expand Down
1 change: 0 additions & 1 deletion crates/elp/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,6 @@ mod tests {
simple_snapshot(
args_vec![
"lint",
"--include-erlc-diagnostics",
"--diagnostic-filter",
"L1318",
"--module",
Expand Down
17 changes: 17 additions & 0 deletions crates/ide/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ pub struct DiagnosticsConfig<'a> {
pub include_otp: bool,
pub compile_options: Vec<CompileOption>,
pub override_compile_options: Vec<CompileOption>,
/// Used in `elp lint` to request erlang service diagnostics if
/// needed.
pub request_erlang_service_diagnostics: bool,
}

impl<'a> DiagnosticsConfig<'a> {
Expand Down Expand Up @@ -477,6 +480,7 @@ impl<'a> DiagnosticsConfig<'a> {
self.disabled = disabled_diagnostics;
self.enabled = allowed_diagnostics;
self.lints_from_config = lint_config.ad_hoc_lints.clone();
self.request_erlang_service_diagnostics = self.request_erlang_service_diagnostics();
Ok(self)
}

Expand Down Expand Up @@ -530,6 +534,19 @@ impl<'a> DiagnosticsConfig<'a> {
self.lints_from_config = lints_from_config.clone();
self
}

/// If any diagnostics are enabled that are produced by the erlang
/// service, tell `elp lint` to request diagnostics from that source.
fn request_erlang_service_diagnostics(&self) -> bool {
lazy_static! {
static ref NEEDS_ERLANG_SERVICE: FxHashSet<DiagnosticCode> =
FxHashSet::from_iter(vec![DiagnosticCode::ErlangService("L1318".to_string())]);
}
self.enabled
.intersection(&NEEDS_ERLANG_SERVICE)
.next()
.is_some()
}
}

// ---------------------------------------------------------------------
Expand Down

0 comments on commit 4d95be1

Please sign in to comment.