Skip to content

Commit 1914b77

Browse files
committed
Don't complete super unless its valid in paths
1 parent d0fa7ab commit 1914b77

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
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: 20 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
@@ -204,8 +210,16 @@ mod tests {
204210
"#]],
205211
);
206212

213+
// FIXME: `self` shouldn't be shown here and the check below
207214
check(
208215
r"use a::$0",
216+
expect![[r#"
217+
kw self
218+
"#]],
219+
);
220+
221+
check(
222+
r"use super::$0",
209223
expect![[r#"
210224
kw self
211225
kw super::
@@ -215,9 +229,8 @@ mod tests {
215229
check(
216230
r"use a::{b, $0}",
217231
expect![[r#"
218-
kw self
219-
kw super::
220-
"#]],
232+
kw self
233+
"#]],
221234
);
222235
}
223236

0 commit comments

Comments
 (0)