Remove redundant completions

This commit is contained in:
Igor Aleksanov 2020-10-12 10:59:15 +03:00
parent 59483c2176
commit 70157f07d9
3 changed files with 70 additions and 4 deletions

View file

@ -116,6 +116,25 @@ pub(crate) fn if_is_prev(element: SyntaxElement) -> bool {
.is_some()
}
pub(crate) fn fn_is_prev(element: SyntaxElement) -> bool {
element
.into_token()
.and_then(|it| previous_non_trivia_token(it))
.filter(|it| it.kind() == FN_KW)
.is_some()
}
/// Check if the token previous to the previous one is `for`.
/// For example, `for _ i<|>` => true.
pub(crate) fn for_is_prev2(element: SyntaxElement) -> bool {
element
.into_token()
.and_then(|it| previous_non_trivia_token(it))
.and_then(|it| previous_non_trivia_token(it))
.filter(|it| it.kind() == FOR_KW)
.is_some()
}
#[test]
fn test_if_is_prev() {
check_pattern_is_applicable(r"if l<|>", if_is_prev);