diff options
Diffstat (limited to 'crates/libeditor/src/completion.rs')
-rw-r--r-- | crates/libeditor/src/completion.rs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/crates/libeditor/src/completion.rs b/crates/libeditor/src/completion.rs index d95c40773..f733cd2b2 100644 --- a/crates/libeditor/src/completion.rs +++ b/crates/libeditor/src/completion.rs | |||
@@ -21,11 +21,10 @@ pub fn scope_completion(file: &File, offset: TextUnit) -> Option<Vec<CompletionI | |||
21 | // Insert a fake ident to get a valid parse tree | 21 | // Insert a fake ident to get a valid parse tree |
22 | let file = { | 22 | let file = { |
23 | let edit = AtomEdit::insert(offset, "intellijRulezz".to_string()); | 23 | let edit = AtomEdit::insert(offset, "intellijRulezz".to_string()); |
24 | // Don't bother with completion if incremental reparse fails | 24 | file.reparse(&edit) |
25 | file.incremental_reparse(&edit)? | ||
26 | }; | 25 | }; |
27 | let name_ref = find_node_at_offset::<ast::NameRef>(file.syntax(), offset)?; | 26 | let name_ref = find_node_at_offset::<ast::NameRef>(file.syntax(), offset)?; |
28 | if !is_ident_expr(name_ref) { | 27 | if !is_single_segment(name_ref) { |
29 | return None; | 28 | return None; |
30 | } | 29 | } |
31 | 30 | ||
@@ -50,11 +49,11 @@ pub fn scope_completion(file: &File, offset: TextUnit) -> Option<Vec<CompletionI | |||
50 | Some(res) | 49 | Some(res) |
51 | } | 50 | } |
52 | 51 | ||
53 | fn is_ident_expr(name_ref: ast::NameRef) -> bool { | 52 | fn is_single_segment(name_ref: ast::NameRef) -> bool { |
54 | match ancestors(name_ref.syntax()).filter_map(ast::Expr::cast).next() { | 53 | match ancestors(name_ref.syntax()).filter_map(ast::Path::cast).next() { |
55 | None => false, | 54 | None => false, |
56 | Some(expr) => { | 55 | Some(path) => { |
57 | expr.syntax().range() == name_ref.syntax().range() | 56 | path.syntax().range() == name_ref.syntax().range() |
58 | } | 57 | } |
59 | } | 58 | } |
60 | } | 59 | } |
@@ -204,6 +203,15 @@ mod tests { | |||
204 | } | 203 | } |
205 | 204 | ||
206 | #[test] | 205 | #[test] |
206 | fn test_complete_type() { | ||
207 | check_scope_completion(r" | ||
208 | struct Foo; | ||
209 | fn x() -> <|> | ||
210 | ", r#"[CompletionItem { name: "Foo", snippet: None }, | ||
211 | CompletionItem { name: "x", snippet: None }]"#) | ||
212 | } | ||
213 | |||
214 | #[test] | ||
207 | fn test_completion_kewords() { | 215 | fn test_completion_kewords() { |
208 | check_snippet_completion(r" | 216 | check_snippet_completion(r" |
209 | fn quux() { | 217 | fn quux() { |