mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
simplify
This commit is contained in:
parent
7de925b8ab
commit
6ec4ea8d9e
@ -18,9 +18,8 @@ use text_edit::Indel;
|
|||||||
use crate::{
|
use crate::{
|
||||||
patterns::{
|
patterns::{
|
||||||
for_is_prev2, has_bind_pat_parent, has_block_expr_parent, has_field_list_parent,
|
for_is_prev2, has_bind_pat_parent, has_block_expr_parent, has_field_list_parent,
|
||||||
has_impl_as_prev_sibling, has_impl_parent, has_item_list_or_source_file_parent,
|
has_impl_parent, has_item_list_or_source_file_parent, has_prev_sibling, has_ref_parent,
|
||||||
has_ref_parent, has_trait_as_prev_sibling, has_trait_parent, inside_impl_trait_block,
|
has_trait_parent, inside_impl_trait_block, is_in_loop_body, is_match_arm, previous_token,
|
||||||
is_in_loop_body, is_match_arm, previous_token,
|
|
||||||
},
|
},
|
||||||
CompletionConfig,
|
CompletionConfig,
|
||||||
};
|
};
|
||||||
@ -44,7 +43,7 @@ pub(crate) enum ImmediateLocation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum PrevSibling {
|
pub(crate) enum PrevSibling {
|
||||||
Trait,
|
Trait,
|
||||||
Impl,
|
Impl,
|
||||||
}
|
}
|
||||||
@ -323,9 +322,9 @@ impl<'a> CompletionContext<'a> {
|
|||||||
self.previous_token = previous_token(syntax_element.clone());
|
self.previous_token = previous_token(syntax_element.clone());
|
||||||
self.in_loop_body = is_in_loop_body(syntax_element.clone());
|
self.in_loop_body = is_in_loop_body(syntax_element.clone());
|
||||||
self.is_match_arm = is_match_arm(syntax_element.clone());
|
self.is_match_arm = is_match_arm(syntax_element.clone());
|
||||||
if has_impl_as_prev_sibling(syntax_element.clone()) {
|
if has_prev_sibling(syntax_element.clone(), IMPL) {
|
||||||
self.prev_sibling = Some(PrevSibling::Impl)
|
self.prev_sibling = Some(PrevSibling::Impl)
|
||||||
} else if has_trait_as_prev_sibling(syntax_element.clone()) {
|
} else if has_prev_sibling(syntax_element.clone(), TRAIT) {
|
||||||
self.prev_sibling = Some(PrevSibling::Trait)
|
self.prev_sibling = Some(PrevSibling::Trait)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ use syntax::{
|
|||||||
algo::non_trivia_sibling,
|
algo::non_trivia_sibling,
|
||||||
ast::{self, LoopBodyOwner},
|
ast::{self, LoopBodyOwner},
|
||||||
match_ast, AstNode, Direction, NodeOrToken, SyntaxElement,
|
match_ast, AstNode, Direction, NodeOrToken, SyntaxElement,
|
||||||
SyntaxKind::*,
|
SyntaxKind::{self, *},
|
||||||
SyntaxNode, SyntaxToken, T,
|
SyntaxNode, SyntaxToken, T,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -73,6 +73,7 @@ fn test_has_block_expr_parent() {
|
|||||||
pub(crate) fn has_bind_pat_parent(element: SyntaxElement) -> bool {
|
pub(crate) fn has_bind_pat_parent(element: SyntaxElement) -> bool {
|
||||||
element.ancestors().any(|it| it.kind() == IDENT_PAT)
|
element.ancestors().any(|it| it.kind() == IDENT_PAT)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_has_bind_pat_parent() {
|
fn test_has_bind_pat_parent() {
|
||||||
check_pattern_is_applicable(r"fn my_fn(m$0) {}", has_bind_pat_parent);
|
check_pattern_is_applicable(r"fn my_fn(m$0) {}", has_bind_pat_parent);
|
||||||
@ -133,20 +134,12 @@ fn test_for_is_prev2() {
|
|||||||
check_pattern_is_applicable(r"for i i$0", for_is_prev2);
|
check_pattern_is_applicable(r"for i i$0", for_is_prev2);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn has_trait_as_prev_sibling(element: SyntaxElement) -> bool {
|
pub(crate) fn has_prev_sibling(element: SyntaxElement, kind: SyntaxKind) -> bool {
|
||||||
previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == TRAIT).is_some()
|
previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == kind).is_some()
|
||||||
}
|
|
||||||
#[test]
|
|
||||||
fn test_has_trait_as_prev_sibling() {
|
|
||||||
check_pattern_is_applicable(r"trait A w$0 {}", has_trait_as_prev_sibling);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn has_impl_as_prev_sibling(element: SyntaxElement) -> bool {
|
|
||||||
previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == IMPL).is_some()
|
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_has_impl_as_prev_sibling() {
|
fn test_has_impl_as_prev_sibling() {
|
||||||
check_pattern_is_applicable(r"impl A w$0 {}", has_impl_as_prev_sibling);
|
check_pattern_is_applicable(r"impl A w$0 {}", |it| has_prev_sibling(it, IMPL));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool {
|
pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user