Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/completions/expr.rs')
| -rw-r--r-- | crates/ide-completion/src/completions/expr.rs | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/crates/ide-completion/src/completions/expr.rs b/crates/ide-completion/src/completions/expr.rs index a7df0ab386..77734c5d6f 100644 --- a/crates/ide-completion/src/completions/expr.rs +++ b/crates/ide-completion/src/completions/expr.rs @@ -9,7 +9,7 @@ use syntax::ast; use crate::{ CompletionContext, Completions, completions::record::add_default_update, - context::{BreakableKind, PathCompletionCtx, PathExprCtx, Qualified}, + context::{PathCompletionCtx, PathExprCtx, Qualified}, }; struct PathCallback<'a, F> { @@ -57,8 +57,8 @@ pub(crate) fn complete_expr_path( let &PathExprCtx { in_block_expr, - in_breakable, after_if_expr, + before_else_kw, in_condition, incomplete_let, after_incomplete_let, @@ -67,6 +67,7 @@ pub(crate) fn complete_expr_path( after_amp, ref is_func_update, ref innermost_ret_ty, + ref innermost_breakable_ty, ref impl_, in_match_guard, .. @@ -125,13 +126,12 @@ pub(crate) fn complete_expr_path( ctx.db, &ctx.scope, &ctx.traits_in_scope(), - Some(ctx.module), None, PathCallback { ctx, acc, add_assoc_item, seen: FxHashSet::default() }, ); // Iterate assoc types separately - ty.iterate_assoc_items(ctx.db, ctx.krate, |item| { + ty.iterate_assoc_items(ctx.db, |item| { if let hir::AssocItem::TypeAlias(ty) = item { acc.add_type_alias(ctx, ty) } @@ -195,13 +195,12 @@ pub(crate) fn complete_expr_path( ctx.db, &ctx.scope, &ctx.traits_in_scope(), - Some(ctx.module), None, PathCallback { ctx, acc, add_assoc_item, seen: FxHashSet::default() }, ); // Iterate assoc types separately - ty.iterate_assoc_items(ctx.db, ctx.krate, |item| { + ty.iterate_assoc_items(ctx.db, |item| { if let hir::AssocItem::TypeAlias(ty) = item { acc.add_type_alias(ctx, ty) } @@ -231,7 +230,6 @@ pub(crate) fn complete_expr_path( ctx.db, &ctx.scope, &ctx.traits_in_scope(), - Some(ctx.module), None, PathCallback { ctx, acc, add_assoc_item, seen: FxHashSet::default() }, ); @@ -296,7 +294,7 @@ pub(crate) fn complete_expr_path( acc, ctx, e, - impl_, + impl_.as_ref(), |acc, ctx, variant, path| { acc.add_qualified_enum_variant(ctx, path_ctx, variant, path) }, @@ -354,7 +352,10 @@ pub(crate) fn complete_expr_path( if !in_block_expr { add_keyword("unsafe", "unsafe {\n $0\n}"); - add_keyword("const", "const {\n $0\n}"); + if !wants_const_token { + // Avoid having two `const` items in `&raw $0` + add_keyword("const", "const {\n $0\n}"); + } } add_keyword("match", "match $1 {\n $0\n}"); add_keyword("while", "while $1 {\n $0\n}"); @@ -386,7 +387,7 @@ pub(crate) fn complete_expr_path( add_keyword("let", "let $1 = $0;"); } - if after_if_expr || after_incomplete_let { + if !before_else_kw && (after_if_expr || after_incomplete_let) { add_keyword("else", "else {\n $0\n}"); } @@ -404,14 +405,21 @@ pub(crate) fn complete_expr_path( add_keyword("mut", "mut "); } - if in_breakable != BreakableKind::None { + if let Some(loop_ty) = innermost_breakable_ty { if in_block_expr { add_keyword("continue", "continue;"); - add_keyword("break", "break;"); } else { add_keyword("continue", "continue"); - add_keyword("break", "break"); } + add_keyword( + "break", + match (loop_ty.is_unit(), in_block_expr) { + (true, true) => "break;", + (true, false) => "break", + (false, true) => "break $0;", + (false, false) => "break $0", + }, + ); } if let Some(ret_ty) = innermost_ret_ty { |