mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
Don't complete super
unless its valid in paths
This commit is contained in:
parent
d0fa7abc50
commit
1914b7723f
3 changed files with 34 additions and 23 deletions
|
@ -39,7 +39,8 @@ pub(crate) fn complete_attribute(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete_attribute_start(acc: &mut Completions, ctx: &CompletionContext, attribute: &ast::Attr) {
|
fn complete_attribute_start(acc: &mut Completions, ctx: &CompletionContext, attribute: &ast::Attr) {
|
||||||
for attr_completion in ATTRIBUTES {
|
let is_inner = attribute.kind() == ast::AttrKind::Inner;
|
||||||
|
for attr_completion in ATTRIBUTES.iter().filter(|compl| is_inner || !compl.prefer_inner) {
|
||||||
let mut item = CompletionItem::new(
|
let mut item = CompletionItem::new(
|
||||||
CompletionKind::Attribute,
|
CompletionKind::Attribute,
|
||||||
ctx.source_range(),
|
ctx.source_range(),
|
||||||
|
|
|
@ -25,9 +25,12 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| {
|
func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| {
|
||||||
|
if let Some(pat) = param.pat() {
|
||||||
let text = param.syntax().text().to_string();
|
let text = param.syntax().text().to_string();
|
||||||
params.entry(text).or_insert(param);
|
let lookup = pat.syntax().text().to_string();
|
||||||
})
|
params.entry(text).or_insert(lookup);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
for node in ctx.token.parent().ancestors() {
|
for node in ctx.token.parent().ancestors() {
|
||||||
|
@ -50,13 +53,7 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
params
|
params.into_iter().for_each(|(label, lookup)| {
|
||||||
.into_iter()
|
|
||||||
.filter_map(|(label, param)| {
|
|
||||||
let lookup = param.pat()?.syntax().text().to_string();
|
|
||||||
Some((label, lookup))
|
|
||||||
})
|
|
||||||
.for_each(|(label, lookup)| {
|
|
||||||
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label)
|
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label)
|
||||||
.kind(CompletionItemKind::Binding)
|
.kind(CompletionItemKind::Binding)
|
||||||
.lookup_by(lookup)
|
.lookup_by(lookup)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
//! Completes keywords.
|
//! Completes keywords.
|
||||||
|
|
||||||
|
use std::iter;
|
||||||
|
|
||||||
use syntax::SyntaxKind;
|
use syntax::SyntaxKind;
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
||||||
|
@ -19,11 +21,15 @@ pub(crate) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC
|
||||||
CompletionItem::new(CompletionKind::Keyword, source_range, "self")
|
CompletionItem::new(CompletionKind::Keyword, source_range, "self")
|
||||||
.kind(CompletionItemKind::Keyword)
|
.kind(CompletionItemKind::Keyword)
|
||||||
.add_to(acc);
|
.add_to(acc);
|
||||||
|
if iter::successors(ctx.path_qual.clone(), |p| p.qualifier())
|
||||||
|
.all(|p| p.segment().and_then(|s| s.super_token()).is_some())
|
||||||
|
{
|
||||||
CompletionItem::new(CompletionKind::Keyword, source_range, "super::")
|
CompletionItem::new(CompletionKind::Keyword, source_range, "super::")
|
||||||
.kind(CompletionItemKind::Keyword)
|
.kind(CompletionItemKind::Keyword)
|
||||||
.insert_text("super::")
|
.insert_text("super::")
|
||||||
.add_to(acc);
|
.add_to(acc);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Suggest .await syntax for types that implement Future trait
|
// Suggest .await syntax for types that implement Future trait
|
||||||
if let Some(receiver) = &ctx.dot_receiver {
|
if let Some(receiver) = &ctx.dot_receiver {
|
||||||
|
@ -204,8 +210,16 @@ mod tests {
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// FIXME: `self` shouldn't be shown here and the check below
|
||||||
check(
|
check(
|
||||||
r"use a::$0",
|
r"use a::$0",
|
||||||
|
expect![[r#"
|
||||||
|
kw self
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
|
||||||
|
check(
|
||||||
|
r"use super::$0",
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
kw self
|
kw self
|
||||||
kw super::
|
kw super::
|
||||||
|
@ -216,7 +230,6 @@ mod tests {
|
||||||
r"use a::{b, $0}",
|
r"use a::{b, $0}",
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
kw self
|
kw self
|
||||||
kw super::
|
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue