aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r--crates/ra_analysis/src/completion/complete_keyword.rs16
1 files changed, 14 insertions, 2 deletions
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
21 21
22 // complete keyword "crate" in use stmt 22 // complete keyword "crate" in use stmt
23 if let (Some(use_item), None) = (&ctx.use_item_syntax, &ctx.path_prefix) { 23 if let (Some(use_item), None) = (&ctx.use_item_syntax, &ctx.path_prefix) {
24 if use_item.use_tree().is_none() { 24 let mut complete_crate = false;
25 let use_tree = use_item.use_tree();
26 if let Some(use_tree) = use_tree {
27 let tree_str = use_tree.syntax().text().to_string();
28 if tree_str != "crate" && "crate".starts_with(&tree_str) {
29 complete_crate = true;
30 }
31 } else {
32 complete_crate = true;
33 }
34 if complete_crate {
25 CompletionItem::new(CompletionKind::Keyword, "crate") 35 CompletionItem::new(CompletionKind::Keyword, "crate")
26 .kind(CompletionItemKind::Keyword) 36 .kind(CompletionItemKind::Keyword)
37 .lookup_by("crate")
27 .add_to(acc); 38 .add_to(acc);
28 } 39 }
29 } 40 }
@@ -280,13 +291,14 @@ mod tests {
280 ) 291 )
281 } 292 }
282 293
294 #[test]
283 fn completes_crate_in_use_stmt() { 295 fn completes_crate_in_use_stmt() {
284 check_keyword_completion( 296 check_keyword_completion(
285 r" 297 r"
286 use <|> 298 use <|>
287 ", 299 ",
288 r#" 300 r#"
289 crate 301 crate "crate"
290 "#, 302 "#,
291 ); 303 );
292 // No completion: lambda isolates control flow 304 // No completion: lambda isolates control flow