aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-30 18:03:18 +0100
committerAleksey Kladov <[email protected]>2018-08-30 18:03:18 +0100
commit49e14a99ed4d0baf849bbd5766f6c16e7d37930c (patch)
tree080b101c51c4f2c5921ee14000950abd65917994 /crates/libeditor/src
parent9fcebbc51284408203c05219a0ee92519f51ea74 (diff)
Complete types
Diffstat (limited to 'crates/libeditor/src')
-rw-r--r--crates/libeditor/src/completion.rs22
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
53fn is_ident_expr(name_ref: ast::NameRef) -> bool { 52fn 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() {