Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/completions/keyword.rs')
-rw-r--r--crates/ide-completion/src/completions/keyword.rs73
1 files changed, 3 insertions, 70 deletions
diff --git a/crates/ide-completion/src/completions/keyword.rs b/crates/ide-completion/src/completions/keyword.rs
index b34545414e..14211f86ba 100644
--- a/crates/ide-completion/src/completions/keyword.rs
+++ b/crates/ide-completion/src/completions/keyword.rs
@@ -5,9 +5,8 @@
use syntax::T;
use crate::{
- context::{PathCompletionCtx, PathKind},
- patterns::ImmediateLocation,
- CompletionContext, CompletionItem, CompletionItemKind, Completions,
+ context::PathKind, patterns::ImmediateLocation, CompletionContext, CompletionItem,
+ CompletionItemKind, Completions,
};
pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) {
@@ -83,75 +82,9 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
add_keyword("struct", "struct $0");
add_keyword("union", "union $1 {\n $0\n}");
}
-
- if ctx.expects_type() {
- return;
- }
-
- if ctx.expects_expression() {
- if !has_block_expr_parent {
- add_keyword("unsafe", "unsafe {\n $0\n}");
- }
- add_keyword("match", "match $1 {\n $0\n}");
- add_keyword("while", "while $1 {\n $0\n}");
- add_keyword("while let", "while let $1 = $2 {\n $0\n}");
- add_keyword("loop", "loop {\n $0\n}");
- add_keyword("if", "if $1 {\n $0\n}");
- add_keyword("if let", "if let $1 = $2 {\n $0\n}");
- add_keyword("for", "for $1 in $2 {\n $0\n}");
- add_keyword("true", "true");
- add_keyword("false", "false");
- }
-
- if ctx.previous_token_is(T![if]) || ctx.previous_token_is(T![while]) || has_block_expr_parent {
- add_keyword("let", "let");
- }
-
- if ctx.after_if() {
- add_keyword("else", "else {\n $0\n}");
- add_keyword("else if", "else if $1 {\n $0\n}");
- }
-
- if ctx.expects_ident_ref_expr() {
- add_keyword("mut", "mut ");
- }
-
- let (can_be_stmt, in_loop_body) = match ctx.path_context() {
- Some(&PathCompletionCtx {
- is_absolute_path: false,
- kind: PathKind::Expr { in_block_expr, in_loop_body, .. },
- ..
- }) => (in_block_expr, in_loop_body),
- _ => return,
- };
-
- if in_loop_body {
- if can_be_stmt {
- add_keyword("continue", "continue;");
- add_keyword("break", "break;");
- } else {
- add_keyword("continue", "continue");
- add_keyword("break", "break");
- }
- }
-
- let fn_def = match &ctx.function_def {
- Some(it) => it,
- None => return,
- };
-
- add_keyword(
- "return",
- match (can_be_stmt, fn_def.ret_type().is_some()) {
- (true, true) => "return $0;",
- (true, false) => "return;",
- (false, true) => "return $0",
- (false, false) => "return",
- },
- )
}
-fn add_keyword(acc: &mut Completions, ctx: &CompletionContext, kw: &str, snippet: &str) {
+pub(super) fn add_keyword(acc: &mut Completions, ctx: &CompletionContext, kw: &str, snippet: &str) {
let mut item = CompletionItem::new(CompletionItemKind::Keyword, ctx.source_range(), kw);
match ctx.config.snippet_cap {