From 49e14a99ed4d0baf849bbd5766f6c16e7d37930c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Aug 2018 20:03:18 +0300 Subject: Complete types --- crates/libeditor/src/completion.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'crates/libeditor') 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(file.syntax(), offset)?; - if !is_ident_expr(name_ref) { + if !is_single_segment(name_ref) { return None; } @@ -50,11 +49,11 @@ pub fn scope_completion(file: &File, offset: TextUnit) -> Option bool { - match ancestors(name_ref.syntax()).filter_map(ast::Expr::cast).next() { +fn is_single_segment(name_ref: ast::NameRef) -> bool { + match ancestors(name_ref.syntax()).filter_map(ast::Path::cast).next() { None => false, - Some(expr) => { - expr.syntax().range() == name_ref.syntax().range() + Some(path) => { + path.syntax().range() == name_ref.syntax().range() } } } @@ -203,6 +202,15 @@ mod tests { CompletionItem { name: "quux", snippet: None }]"#); } + #[test] + fn test_complete_type() { + check_scope_completion(r" + struct Foo; + fn x() -> <|> + ", r#"[CompletionItem { name: "Foo", snippet: None }, + CompletionItem { name: "x", snippet: None }]"#) + } + #[test] fn test_completion_kewords() { check_snippet_completion(r" -- cgit v1.2.3