Skip to content

Commit

Permalink
Pick up meta_only diagnostic codes in FromStr too
Browse files Browse the repository at this point in the history
Summary: Now that we have multiple meta-only diagnostic codes, implement the same serlialization/deserialization mechanism for them so they can be used in `.elp_lint.toml` config files.

Reviewed By: ilya-klyuchnikov

Differential Revision: D52069905

fbshipit-source-id: 84b62ba12e434358e647da2fdb0ae38fc6b96f24
  • Loading branch information
alanz authored and facebook-github-bot committed Dec 12, 2023
1 parent 94267e1 commit 4d6e027
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions crates/ide/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ pub enum Category {
}

#[derive(Clone, Debug, PartialEq, Eq, Hash, EnumIter)]
// pub struct DiagnosticCode(pub String);
pub enum DiagnosticCode {
DefaultCodeForEnumIter,
HeadMismatch,
Expand Down Expand Up @@ -432,16 +431,17 @@ impl DiagnosticCode {
}

pub fn maybe_from_string(s: &String) -> Option<DiagnosticCode> {
if let Some(r) = DIAGNOSTIC_CODE_LOOKUPS.get(s) {
Some(r.clone())
} else {
// Look for ErlangService and AdHoc
if let Some(code) = Self::is_adhoc(s) {
Some(DiagnosticCode::AdHoc(code))
} else {
Self::is_erlang_service(s).map(DiagnosticCode::ErlangService)
}
}
DIAGNOSTIC_CODE_LOOKUPS
.get(s).cloned()
// @fb-only: .or_else(|| MetaOnlyDiagnosticCode::from_str(s).ok().map(|c| DiagnosticCode::MetaOnly(c)))
.or_else( ||
// Look for ErlangService and AdHoc
if let Some(code) = Self::is_adhoc(s) {
Some(DiagnosticCode::AdHoc(code))
} else {
Self::is_erlang_service(s).map(DiagnosticCode::ErlangService)
},
)
}

pub fn namespace(code: &String) -> Option<String> {
Expand Down Expand Up @@ -508,6 +508,7 @@ impl FromStr for DiagnosticCode {
}
}
}

impl From<&str> for DiagnosticCode {
fn from(str: &str) -> Self {
match DiagnosticCode::from_str(str) {
Expand Down

0 comments on commit 4d6e027

Please sign in to comment.