From fc2d7d1e1f03faa4566dea8b60eca860bcf9eb04 Mon Sep 17 00:00:00 2001 From: gfreezy Date: Tue, 1 Jan 2019 21:55:27 +0800 Subject: complete crate in use stmt --- .../ra_analysis/src/completion/complete_keyword.rs | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (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 d70fdaada..f51d77f27 100644 --- a/crates/ra_analysis/src/completion/complete_keyword.rs +++ b/crates/ra_analysis/src/completion/complete_keyword.rs @@ -18,6 +18,16 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte if !ctx.is_trivial_path { return; } + + // 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() { + CompletionItem::new(CompletionKind::Keyword, "crate") + .kind(CompletionItemKind::Keyword) + .add_to(acc); + } + } + let fn_def = match ctx.function_syntax { Some(it) => it, None => return, @@ -269,4 +279,23 @@ mod tests { "#, ) } + + fn completes_crate_in_use_stmt() { + check_keyword_completion( + r" + use <|> + ", + r#" + crate + "#, + ); + // No completion: lambda isolates control flow + check_keyword_completion( + r" + use a<|> + ", + r#" + "#, + ); + } } -- cgit v1.2.3