Skip to content

Commit

Permalink
feat: warnings for incorrect predicate usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ribru17 committed Oct 29, 2024
1 parent 1fc1335 commit 666c6cb
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,29 @@ const DIAGNOSTICS_QUERY: &str = r#"
(field_definition name: (identifier) @f)
(parameters (capture) @c)
(_ "(" ")" @p)
(predicate
name: (identifier) @_name
(parameters
.
; NOTE: Technically this can be a "_" but it doesn't work with anchors. Also rare?
[(string) (identifier)] @arg)
(#any-of? @_name "eq" "not-eq" "any-eq" "any-not-eq"
"match" "not-match" "any-match" "any-not-match"
"any-of" "not-any-of"))
(predicate
name: (identifier) @_name
(#any-of? @_name "eq" "not-eq" "any-eq" "any-not-eq")
(parameters
(capture)
_
_+ @bad_eq))
(predicate
name: (identifier) @_name
(#any-of? @_name "match" "not-match" "any-match" "any-not-match")
(parameters
(capture)
_
_+ @bad_match))
"#;

pub fn get_diagnostics(
Expand Down Expand Up @@ -336,6 +359,32 @@ pub fn get_diagnostics(
})
}
}
"arg" => {
diagnostics.push(Diagnostic {
message: "First argument must be a capture".to_owned(),
range,
severity: Some(DiagnosticSeverity::WARNING),
..Default::default()
});
}
"bad_eq" => {
diagnostics.push(Diagnostic {
message: r##""#eq?" family predicates cannot accept multiple arguments. Consider using "#any-of?"."##.to_owned(),
range,
severity: Some(DiagnosticSeverity::WARNING),
..Default::default()
});
}
"bad_match" => {
diagnostics.push(Diagnostic {
message:
r##""#match?" family predicates cannot accept multiple arguments."##
.to_owned(),
range,
severity: Some(DiagnosticSeverity::WARNING),
..Default::default()
});
}
_ => {}
}
}
Expand Down

0 comments on commit 666c6cb

Please sign in to comment.