diff options
Diffstat (limited to 'crates/ide_completion/src/patterns.rs')
-rw-r--r-- | crates/ide_completion/src/patterns.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/crates/ide_completion/src/patterns.rs b/crates/ide_completion/src/patterns.rs index 72e67e3c4..345977d48 100644 --- a/crates/ide_completion/src/patterns.rs +++ b/crates/ide_completion/src/patterns.rs | |||
@@ -19,6 +19,7 @@ pub(crate) enum ImmediatePrevSibling { | |||
19 | IfExpr, | 19 | IfExpr, |
20 | TraitDefName, | 20 | TraitDefName, |
21 | ImplDefType, | 21 | ImplDefType, |
22 | Visibility, | ||
22 | } | 23 | } |
23 | 24 | ||
24 | /// Direct parent "thing" of what we are currently completing. | 25 | /// Direct parent "thing" of what we are currently completing. |
@@ -79,6 +80,17 @@ pub(crate) fn determine_prev_sibling(name_like: &ast::NameLike) -> Option<Immedi | |||
79 | _ => node, | 80 | _ => node, |
80 | }; | 81 | }; |
81 | let prev_sibling = non_trivia_sibling(node.into(), Direction::Prev)?.into_node()?; | 82 | let prev_sibling = non_trivia_sibling(node.into(), Direction::Prev)?.into_node()?; |
83 | if prev_sibling.kind() == ERROR { | ||
84 | let prev_sibling = prev_sibling.first_child()?; | ||
85 | let res = match_ast! { | ||
86 | match prev_sibling { | ||
87 | // vis followed by random ident will always error the parser | ||
88 | ast::Visibility(_it) => ImmediatePrevSibling::Visibility, | ||
89 | _ => return None, | ||
90 | } | ||
91 | }; | ||
92 | return Some(res); | ||
93 | } | ||
82 | let res = match_ast! { | 94 | let res = match_ast! { |
83 | match prev_sibling { | 95 | match prev_sibling { |
84 | ast::ExprStmt(it) => { | 96 | ast::ExprStmt(it) => { |
@@ -421,4 +433,9 @@ mod tests { | |||
421 | check_prev_sibling(r"fn foo() { if true {} w$0", ImmediatePrevSibling::IfExpr); | 433 | check_prev_sibling(r"fn foo() { if true {} w$0", ImmediatePrevSibling::IfExpr); |
422 | check_prev_sibling(r"fn foo() { if true {}; w$0", None); | 434 | check_prev_sibling(r"fn foo() { if true {}; w$0", None); |
423 | } | 435 | } |
436 | |||
437 | #[test] | ||
438 | fn test_vis_prev_sibling() { | ||
439 | check_prev_sibling(r"pub w$0", ImmediatePrevSibling::Visibility); | ||
440 | } | ||
424 | } | 441 | } |