From 2987e05f158207f63e2bc4ac87c0c2fbb7e61002 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 7 Jun 2021 20:45:17 +0200 Subject: simplify --- crates/ide_completion/src/completions/keyword.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'crates/ide_completion/src/completions/keyword.rs') diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs index 0ca97a0e4..ba13d3707 100644 --- a/crates/ide_completion/src/completions/keyword.rs +++ b/crates/ide_completion/src/completions/keyword.rs @@ -5,8 +5,8 @@ use std::iter; use syntax::{SyntaxKind, T}; use crate::{ - patterns::ImmediateLocation, CompletionContext, CompletionItem, CompletionItemKind, - CompletionKind, Completions, + context::PathCompletionContext, patterns::ImmediateLocation, CompletionContext, CompletionItem, + CompletionItemKind, CompletionKind, Completions, }; pub(crate) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionContext) { @@ -128,8 +128,15 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte add_keyword("mut", "mut "); } - if ctx.in_loop_body { - if ctx.can_be_stmt() { + let (can_be_stmt, in_loop_body) = match ctx.path_context { + Some(PathCompletionContext { + is_trivial_path: true, can_be_stmt, in_loop_body, .. + }) => (can_be_stmt, in_loop_body), + _ => return, + }; + + if in_loop_body { + if can_be_stmt { add_keyword("continue", "continue;"); add_keyword("break", "break;"); } else { @@ -138,9 +145,6 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte } } - if !ctx.is_trivial_path() { - return; - } let fn_def = match &ctx.function_def { Some(it) => it, None => return, @@ -148,7 +152,7 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte add_keyword( "return", - match (ctx.can_be_stmt(), fn_def.ret_type().is_some()) { + match (can_be_stmt, fn_def.ret_type().is_some()) { (true, true) => "return $0;", (true, false) => "return;", (false, true) => "return $0", -- cgit v1.2.3