mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 05:38:46 +00:00
Merge #7866
7866: Complete `while let` r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
7275750e42
4 changed files with 45 additions and 32 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| {
|
||||||
let text = param.syntax().text().to_string();
|
if let Some(pat) = param.pat() {
|
||||||
params.entry(text).or_insert(param);
|
let text = param.syntax().text().to_string();
|
||||||
})
|
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,18 +53,12 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
params
|
params.into_iter().for_each(|(label, lookup)| {
|
||||||
.into_iter()
|
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label)
|
||||||
.filter_map(|(label, param)| {
|
.kind(CompletionItemKind::Binding)
|
||||||
let lookup = param.pat()?.syntax().text().to_string();
|
.lookup_by(lookup)
|
||||||
Some((label, lookup))
|
.add_to(acc)
|
||||||
})
|
});
|
||||||
.for_each(|(label, lookup)| {
|
|
||||||
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label)
|
|
||||||
.kind(CompletionItemKind::Binding)
|
|
||||||
.lookup_by(lookup)
|
|
||||||
.add_to(acc)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -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,10 +21,14 @@ 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);
|
||||||
CompletionItem::new(CompletionKind::Keyword, source_range, "super::")
|
if iter::successors(ctx.path_qual.clone(), |p| p.qualifier())
|
||||||
.kind(CompletionItemKind::Keyword)
|
.all(|p| p.segment().and_then(|s| s.super_token()).is_some())
|
||||||
.insert_text("super::")
|
{
|
||||||
.add_to(acc);
|
CompletionItem::new(CompletionKind::Keyword, source_range, "super::")
|
||||||
|
.kind(CompletionItemKind::Keyword)
|
||||||
|
.insert_text("super::")
|
||||||
|
.add_to(acc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Suggest .await syntax for types that implement Future trait
|
// Suggest .await syntax for types that implement Future trait
|
||||||
|
@ -85,6 +91,7 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
|
||||||
if ctx.is_expr {
|
if ctx.is_expr {
|
||||||
add_keyword(ctx, acc, "match", "match $0 {}");
|
add_keyword(ctx, acc, "match", "match $0 {}");
|
||||||
add_keyword(ctx, acc, "while", "while $0 {}");
|
add_keyword(ctx, acc, "while", "while $0 {}");
|
||||||
|
add_keyword(ctx, acc, "while let", "while let $1 = $0 {}");
|
||||||
add_keyword(ctx, acc, "loop", "loop {$0}");
|
add_keyword(ctx, acc, "loop", "loop {$0}");
|
||||||
add_keyword(ctx, acc, "if", "if $0 {}");
|
add_keyword(ctx, acc, "if", "if $0 {}");
|
||||||
add_keyword(ctx, acc, "if let", "if let $1 = $0 {}");
|
add_keyword(ctx, acc, "if let", "if let $1 = $0 {}");
|
||||||
|
@ -204,8 +211,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::
|
||||||
|
@ -215,9 +230,8 @@ mod tests {
|
||||||
check(
|
check(
|
||||||
r"use a::{b, $0}",
|
r"use a::{b, $0}",
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
kw self
|
kw self
|
||||||
kw super::
|
"#]],
|
||||||
"#]],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -256,6 +270,7 @@ mod tests {
|
||||||
kw trait
|
kw trait
|
||||||
kw match
|
kw match
|
||||||
kw while
|
kw while
|
||||||
|
kw while let
|
||||||
kw loop
|
kw loop
|
||||||
kw if
|
kw if
|
||||||
kw if let
|
kw if let
|
||||||
|
@ -283,6 +298,7 @@ mod tests {
|
||||||
kw trait
|
kw trait
|
||||||
kw match
|
kw match
|
||||||
kw while
|
kw while
|
||||||
|
kw while let
|
||||||
kw loop
|
kw loop
|
||||||
kw if
|
kw if
|
||||||
kw if let
|
kw if let
|
||||||
|
@ -310,6 +326,7 @@ mod tests {
|
||||||
kw trait
|
kw trait
|
||||||
kw match
|
kw match
|
||||||
kw while
|
kw while
|
||||||
|
kw while let
|
||||||
kw loop
|
kw loop
|
||||||
kw if
|
kw if
|
||||||
kw if let
|
kw if let
|
||||||
|
@ -344,6 +361,7 @@ fn quux() -> i32 {
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
kw match
|
kw match
|
||||||
kw while
|
kw while
|
||||||
|
kw while let
|
||||||
kw loop
|
kw loop
|
||||||
kw if
|
kw if
|
||||||
kw if let
|
kw if let
|
||||||
|
@ -393,6 +411,7 @@ fn quux() -> i32 {
|
||||||
kw trait
|
kw trait
|
||||||
kw match
|
kw match
|
||||||
kw while
|
kw while
|
||||||
|
kw while let
|
||||||
kw loop
|
kw loop
|
||||||
kw if
|
kw if
|
||||||
kw if let
|
kw if let
|
||||||
|
@ -552,6 +571,7 @@ pub mod future {
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
kw match
|
kw match
|
||||||
kw while
|
kw while
|
||||||
|
kw while let
|
||||||
kw loop
|
kw loop
|
||||||
kw if
|
kw if
|
||||||
kw if let
|
kw if let
|
||||||
|
@ -611,6 +631,7 @@ fn foo() {
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
kw match
|
kw match
|
||||||
kw while
|
kw while
|
||||||
|
kw while let
|
||||||
kw loop
|
kw loop
|
||||||
kw if
|
kw if
|
||||||
kw if let
|
kw if let
|
||||||
|
|
|
@ -81,9 +81,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
match item {
|
match item {
|
||||||
hir::AssocItem::Function(func) => {
|
hir::AssocItem::Function(func) => acc.add_function(ctx, func, None),
|
||||||
acc.add_function(ctx, func, None);
|
|
||||||
}
|
|
||||||
hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
|
hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
|
||||||
hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
|
hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
|
||||||
}
|
}
|
||||||
|
@ -110,9 +108,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
match item {
|
match item {
|
||||||
hir::AssocItem::Function(func) => {
|
hir::AssocItem::Function(func) => acc.add_function(ctx, func, None),
|
||||||
acc.add_function(ctx, func, None);
|
|
||||||
}
|
|
||||||
hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
|
hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
|
||||||
hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
|
hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
|
||||||
}
|
}
|
||||||
|
@ -143,9 +139,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
|
||||||
// them.
|
// them.
|
||||||
if seen.insert(item) {
|
if seen.insert(item) {
|
||||||
match item {
|
match item {
|
||||||
hir::AssocItem::Function(func) => {
|
hir::AssocItem::Function(func) => acc.add_function(ctx, func, None),
|
||||||
acc.add_function(ctx, func, None);
|
|
||||||
}
|
|
||||||
hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
|
hir::AssocItem::Const(ct) => acc.add_const(ctx, ct),
|
||||||
hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
|
hir::AssocItem::TypeAlias(ty) => acc.add_type_alias(ctx, ty),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue