Skip to content

Commit 7275750

Browse files
bors[bot]Veykril
andauthored
Merge #7866
7866: Complete `while let` r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 parents d0fa7ab + 02e9440 commit 7275750

File tree

4 files changed

+45
-32
lines changed

4 files changed

+45
-32
lines changed

crates/ide_completion/src/completions/attribute.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
3939
}
4040

4141
fn 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) {
4344
let mut item = CompletionItem::new(
4445
CompletionKind::Attribute,
4546
ctx.source_range(),

crates/ide_completion/src/completions/fn_param.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
2525
return;
2626
}
2727
func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| {
28-
let text = param.syntax().text().to_string();
29-
params.entry(text).or_insert(param);
30-
})
28+
if let Some(pat) = param.pat() {
29+
let text = param.syntax().text().to_string();
30+
let lookup = pat.syntax().text().to_string();
31+
params.entry(text).or_insert(lookup);
32+
}
33+
});
3134
};
3235

3336
for node in ctx.token.parent().ancestors() {
@@ -50,18 +53,12 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
5053
};
5154
}
5255

53-
params
54-
.into_iter()
55-
.filter_map(|(label, param)| {
56-
let lookup = param.pat()?.syntax().text().to_string();
57-
Some((label, lookup))
58-
})
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-
});
56+
params.into_iter().for_each(|(label, lookup)| {
57+
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label)
58+
.kind(CompletionItemKind::Binding)
59+
.lookup_by(lookup)
60+
.add_to(acc)
61+
});
6562
}
6663

6764
#[cfg(test)]

crates/ide_completion/src/completions/keyword.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Completes keywords.
22
3+
use std::iter;
4+
35
use syntax::SyntaxKind;
46
use test_utils::mark;
57

@@ -19,10 +21,14 @@ pub(crate) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC
1921
CompletionItem::new(CompletionKind::Keyword, source_range, "self")
2022
.kind(CompletionItemKind::Keyword)
2123
.add_to(acc);
22-
CompletionItem::new(CompletionKind::Keyword, source_range, "super::")
23-
.kind(CompletionItemKind::Keyword)
24-
.insert_text("super::")
25-
.add_to(acc);
24+
if iter::successors(ctx.path_qual.clone(), |p| p.qualifier())
25+
.all(|p| p.segment().and_then(|s| s.super_token()).is_some())
26+
{
27+
CompletionItem::new(CompletionKind::Keyword, source_range, "super::")
28+
.kind(CompletionItemKind::Keyword)
29+
.insert_text("super::")
30+
.add_to(acc);
31+
}
2632
}
2733

2834
// Suggest .await syntax for types that implement Future trait
@@ -85,6 +91,7 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
8591
if ctx.is_expr {
8692
add_keyword(ctx, acc, "match", "match $0 {}");
8793
add_keyword(ctx, acc, "while", "while $0 {}");
94+
add_keyword(ctx, acc, "while let", "while let $1 = $0 {}");
8895
add_keyword(ctx, acc, "loop", "loop {$0}");
8996
add_keyword(ctx, acc, "if", "if $0 {}");
9097
add_keyword(ctx, acc, "if let", "if let $1 = $0 {}");
@@ -204,8 +211,16 @@ mod tests {
204211
"#]],
205212
);
206213

214+
// FIXME: `self` shouldn't be shown here and the check below
207215
check(
208216
r"use a::$0",
217+
expect![[r#"
218+
kw self
219+
"#]],
220+
);
221+
222+
check(
223+
r"use super::$0",
209224
expect![[r#"
210225
kw self
211226
kw super::
@@ -215,9 +230,8 @@ mod tests {
215230
check(
216231
r"use a::{b, $0}",
217232
expect![[r#"
218-
kw self
219-
kw super::
220-
"#]],
233+
kw self
234+
"#]],
221235
);
222236
}
223237

@@ -256,6 +270,7 @@ mod tests {
256270
kw trait
257271
kw match
258272
kw while
273+
kw while let
259274
kw loop
260275
kw if
261276
kw if let
@@ -283,6 +298,7 @@ mod tests {
283298
kw trait
284299
kw match
285300
kw while
301+
kw while let
286302
kw loop
287303
kw if
288304
kw if let
@@ -310,6 +326,7 @@ mod tests {
310326
kw trait
311327
kw match
312328
kw while
329+
kw while let
313330
kw loop
314331
kw if
315332
kw if let
@@ -344,6 +361,7 @@ fn quux() -> i32 {
344361
expect![[r#"
345362
kw match
346363
kw while
364+
kw while let
347365
kw loop
348366
kw if
349367
kw if let
@@ -393,6 +411,7 @@ fn quux() -> i32 {
393411
kw trait
394412
kw match
395413
kw while
414+
kw while let
396415
kw loop
397416
kw if
398417
kw if let
@@ -552,6 +571,7 @@ pub mod future {
552571
expect![[r#"
553572
kw match
554573
kw while
574+
kw while let
555575
kw loop
556576
kw if
557577
kw if let
@@ -611,6 +631,7 @@ fn foo() {
611631
expect![[r#"
612632
kw match
613633
kw while
634+
kw while let
614635
kw loop
615636
kw if
616637
kw if let

crates/ide_completion/src/completions/qualified_path.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
8181
return None;
8282
}
8383
match item {
84-
hir::AssocItem::Function(func) => {
85-
acc.add_function(ctx, func, None);
86-
}
84+
hir::AssocItem::Function(func) => acc.add_function(ctx, func, None),
8785
hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
8886
hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
8987
}
@@ -110,9 +108,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
110108
continue;
111109
}
112110
match item {
113-
hir::AssocItem::Function(func) => {
114-
acc.add_function(ctx, func, None);
115-
}
111+
hir::AssocItem::Function(func) => acc.add_function(ctx, func, None),
116112
hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
117113
hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
118114
}
@@ -143,9 +139,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
143139
// them.
144140
if seen.insert(item) {
145141
match item {
146-
hir::AssocItem::Function(func) => {
147-
acc.add_function(ctx, func, None);
148-
}
142+
hir::AssocItem::Function(func) => acc.add_function(ctx, func, None),
149143
hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
150144
hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
151145
}

0 commit comments

Comments
 (0)