aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ide_completion/src/completions/attribute.rs3
-rw-r--r--crates/ide_completion/src/completions/fn_param.rs27
-rw-r--r--crates/ide_completion/src/completions/keyword.rs35
-rw-r--r--crates/ide_completion/src/completions/qualified_path.rs12
4 files changed, 45 insertions, 32 deletions
diff --git a/crates/ide_completion/src/completions/attribute.rs b/crates/ide_completion/src/completions/attribute.rs
index 3a5bc4381..cb05e85fc 100644
--- a/crates/ide_completion/src/completions/attribute.rs
+++ b/crates/ide_completion/src/completions/attribute.rs
@@ -39,7 +39,8 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
39} 39}
40 40
41fn complete_attribute_start(acc: &mut Completions, ctx: &CompletionContext, attribute: &ast::Attr) { 41fn complete_attribute_start(acc: &mut Completions, ctx: &CompletionContext, attribute: &ast::Attr) {
42 for attr_completion in ATTRIBUTES { 42 let is_inner = attribute.kind() == ast::AttrKind::Inner;
43 for attr_completion in ATTRIBUTES.iter().filter(|compl| is_inner || !compl.prefer_inner) {
43 let mut item = CompletionItem::new( 44 let mut item = CompletionItem::new(
44 CompletionKind::Attribute, 45 CompletionKind::Attribute,
45 ctx.source_range(), 46 ctx.source_range(),
diff --git a/crates/ide_completion/src/completions/fn_param.rs b/crates/ide_completion/src/completions/fn_param.rs
index 38e33a93e..1bcc8727f 100644
--- a/crates/ide_completion/src/completions/fn_param.rs
+++ b/crates/ide_completion/src/completions/fn_param.rs
@@ -25,9 +25,12 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
25 return; 25 return;
26 } 26 }
27 func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| { 27 func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| {
28 let text = param.syntax().text().to_string(); 28 if let Some(pat) = param.pat() {
29 params.entry(text).or_insert(param); 29 let text = param.syntax().text().to_string();
30 }) 30 let lookup = pat.syntax().text().to_string();
31 params.entry(text).or_insert(lookup);
32 }
33 });
31 }; 34 };
32 35
33 for node in ctx.token.parent().ancestors() { 36 for node in ctx.token.parent().ancestors() {
@@ -50,18 +53,12 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
50 }; 53 };
51 } 54 }
52 55
53 params 56 params.into_iter().for_each(|(label, lookup)| {
54 .into_iter() 57 CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label)
55 .filter_map(|(label, param)| { 58 .kind(CompletionItemKind::Binding)
56 let lookup = param.pat()?.syntax().text().to_string(); 59 .lookup_by(lookup)
57 Some((label, lookup)) 60 .add_to(acc)
58 }) 61 });
59 .for_each(|(label, lookup)| {
60 CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label)
61 .kind(CompletionItemKind::Binding)
62 .lookup_by(lookup)
63 .add_to(acc)
64 });
65} 62}
66 63
67#[cfg(test)] 64#[cfg(test)]
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs
index eb81f9765..03c6dd454 100644
--- a/crates/ide_completion/src/completions/keyword.rs
+++ b/crates/ide_completion/src/completions/keyword.rs
@@ -1,5 +1,7 @@
1//! Completes keywords. 1//! Completes keywords.
2 2
3use std::iter;
4
3use syntax::SyntaxKind; 5use syntax::SyntaxKind;
4use test_utils::mark; 6use test_utils::mark;
5 7
@@ -19,10 +21,14 @@ pub(crate) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC
19 CompletionItem::new(CompletionKind::Keyword, source_range, "self") 21 CompletionItem::new(CompletionKind::Keyword, source_range, "self")
20 .kind(CompletionItemKind::Keyword) 22 .kind(CompletionItemKind::Keyword)
21 .add_to(acc); 23 .add_to(acc);
22 CompletionItem::new(CompletionKind::Keyword, source_range, "super::") 24 if iter::successors(ctx.path_qual.clone(), |p| p.qualifier())
23 .kind(CompletionItemKind::Keyword) 25 .all(|p| p.segment().and_then(|s| s.super_token()).is_some())
24 .insert_text("super::") 26 {
25 .add_to(acc); 27 CompletionItem::new(CompletionKind::Keyword, source_range, "super::")
28 .kind(CompletionItemKind::Keyword)
29 .insert_text("super::")
30 .add_to(acc);
31 }
26 } 32 }
27 33
28 // Suggest .await syntax for types that implement Future trait 34 // Suggest .await syntax for types that implement Future trait
@@ -85,6 +91,7 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
85 if ctx.is_expr { 91 if ctx.is_expr {
86 add_keyword(ctx, acc, "match", "match $0 {}"); 92 add_keyword(ctx, acc, "match", "match $0 {}");
87 add_keyword(ctx, acc, "while", "while $0 {}"); 93 add_keyword(ctx, acc, "while", "while $0 {}");
94 add_keyword(ctx, acc, "while let", "while let $1 = $0 {}");
88 add_keyword(ctx, acc, "loop", "loop {$0}"); 95 add_keyword(ctx, acc, "loop", "loop {$0}");
89 add_keyword(ctx, acc, "if", "if $0 {}"); 96 add_keyword(ctx, acc, "if", "if $0 {}");
90 add_keyword(ctx, acc, "if let", "if let $1 = $0 {}"); 97 add_keyword(ctx, acc, "if let", "if let $1 = $0 {}");
@@ -204,9 +211,17 @@ mod tests {
204 "#]], 211 "#]],
205 ); 212 );
206 213
214 // FIXME: `self` shouldn't be shown here and the check below
207 check( 215 check(
208 r"use a::$0", 216 r"use a::$0",
209 expect![[r#" 217 expect![[r#"
218 kw self
219 "#]],
220 );
221
222 check(
223 r"use super::$0",
224 expect![[r#"
210 kw self 225 kw self
211 kw super:: 226 kw super::
212 "#]], 227 "#]],
@@ -215,9 +230,8 @@ mod tests {
215 check( 230 check(
216 r"use a::{b, $0}", 231 r"use a::{b, $0}",
217 expect![[r#" 232 expect![[r#"
218 kw self 233 kw self
219 kw super:: 234 "#]],
220 "#]],
221 ); 235 );
222 } 236 }
223 237
@@ -256,6 +270,7 @@ mod tests {
256 kw trait 270 kw trait
257 kw match 271 kw match
258 kw while 272 kw while
273 kw while let
259 kw loop 274 kw loop
260 kw if 275 kw if
261 kw if let 276 kw if let
@@ -283,6 +298,7 @@ mod tests {
283 kw trait 298 kw trait
284 kw match 299 kw match
285 kw while 300 kw while
301 kw while let
286 kw loop 302 kw loop
287 kw if 303 kw if
288 kw if let 304 kw if let
@@ -310,6 +326,7 @@ mod tests {
310 kw trait 326 kw trait
311 kw match 327 kw match
312 kw while 328 kw while
329 kw while let
313 kw loop 330 kw loop
314 kw if 331 kw if
315 kw if let 332 kw if let
@@ -344,6 +361,7 @@ fn quux() -> i32 {
344 expect![[r#" 361 expect![[r#"
345 kw match 362 kw match
346 kw while 363 kw while
364 kw while let
347 kw loop 365 kw loop
348 kw if 366 kw if
349 kw if let 367 kw if let
@@ -393,6 +411,7 @@ fn quux() -> i32 {
393 kw trait 411 kw trait
394 kw match 412 kw match
395 kw while 413 kw while
414 kw while let
396 kw loop 415 kw loop
397 kw if 416 kw if
398 kw if let 417 kw if let
@@ -552,6 +571,7 @@ pub mod future {
552 expect![[r#" 571 expect![[r#"
553 kw match 572 kw match
554 kw while 573 kw while
574 kw while let
555 kw loop 575 kw loop
556 kw if 576 kw if
557 kw if let 577 kw if let
@@ -611,6 +631,7 @@ fn foo() {
611 expect![[r#" 631 expect![[r#"
612 kw match 632 kw match
613 kw while 633 kw while
634 kw while let
614 kw loop 635 kw loop
615 kw if 636 kw if
616 kw if let 637 kw if let
diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs
index 2afa6979e..72fb757b1 100644
--- a/crates/ide_completion/src/completions/qualified_path.rs
+++ b/crates/ide_completion/src/completions/qualified_path.rs
@@ -81,9 +81,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
81 return None; 81 return None;
82 } 82 }
83 match item { 83 match item {
84 hir::AssocItem::Function(func) => { 84 hir::AssocItem::Function(func) => acc.add_function(ctx, func, None),
85 acc.add_function(ctx, func, None);
86 }
87 hir::AssocItem::Const(ct) => acc.add_const(ctx, ct), 85 hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
88 hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty), 86 hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
89 } 87 }
@@ -110,9 +108,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
110 continue; 108 continue;
111 } 109 }
112 match item { 110 match item {
113 hir::AssocItem::Function(func) => { 111 hir::AssocItem::Function(func) => acc.add_function(ctx, func, None),
114 acc.add_function(ctx, func, None);
115 }
116 hir::AssocItem::Const(ct) => acc.add_const(ctx, ct), 112 hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
117 hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty), 113 hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
118 } 114 }
@@ -143,9 +139,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
143 // them. 139 // them.
144 if seen.insert(item) { 140 if seen.insert(item) {
145 match item { 141 match item {
146 hir::AssocItem::Function(func) => { 142 hir::AssocItem::Function(func) => acc.add_function(ctx, func, None),
147 acc.add_function(ctx, func, None);
148 }
149 hir::AssocItem::Const(ct) => acc.add_const(ctx, ct), 143 hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
150 hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty), 144 hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
151 } 145 }