From f408b1caa3acdaf7b05498963e70da7f662bf2e3 Mon Sep 17 00:00:00 2001 From: gfreezy Date: Tue, 1 Jan 2019 22:10:11 +0800 Subject: complete "use crate" for "use cr" too --- crates/ra_analysis/src/completion/complete_keyword.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'crates/ra_analysis/src/completion') diff --git a/crates/ra_analysis/src/completion/complete_keyword.rs b/crates/ra_analysis/src/completion/complete_keyword.rs index f51d77f27..a6fbd1e81 100644 --- a/crates/ra_analysis/src/completion/complete_keyword.rs +++ b/crates/ra_analysis/src/completion/complete_keyword.rs @@ -21,9 +21,20 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte // complete keyword "crate" in use stmt if let (Some(use_item), None) = (&ctx.use_item_syntax, &ctx.path_prefix) { - if use_item.use_tree().is_none() { + let mut complete_crate = false; + let use_tree = use_item.use_tree(); + if let Some(use_tree) = use_tree { + let tree_str = use_tree.syntax().text().to_string(); + if tree_str != "crate" && "crate".starts_with(&tree_str) { + complete_crate = true; + } + } else { + complete_crate = true; + } + if complete_crate { CompletionItem::new(CompletionKind::Keyword, "crate") .kind(CompletionItemKind::Keyword) + .lookup_by("crate") .add_to(acc); } } @@ -280,13 +291,14 @@ mod tests { ) } + #[test] fn completes_crate_in_use_stmt() { check_keyword_completion( r" use <|> ", r#" - crate + crate "crate" "#, ); // No completion: lambda isolates control flow -- cgit v1.2.3