aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/completion
diff options
context:
space:
mode:
authorgfreezy <[email protected]>2019-01-01 14:10:11 +0000
committergfreezy <[email protected]>2019-01-01 14:10:11 +0000
commitf408b1caa3acdaf7b05498963e70da7f662bf2e3 (patch)
treed0878a66e5dd011ef84c191c49f189e754ef155c /crates/ra_analysis/src/completion
parentfc2d7d1e1f03faa4566dea8b60eca860bcf9eb04 (diff)
complete "use crate" for "use cr" too
Diffstat (limited to 'crates/ra_analysis/src/completion')
-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