aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-05-27 01:54:49 +0100
committerLukas Wirth <[email protected]>2021-05-27 01:54:49 +0100
commit7de925b8abcf0d26869dc96f346510af61663edf (patch)
tree38bcf6bc8d2cabb051b127e2f1f6cd2a9b94027c /crates/ide_completion/src/completions
parentd6ed315806e23d9ebda96ecfbe13da2154a2289c (diff)
Collapse more CompletionContext booleans into enums
Diffstat (limited to 'crates/ide_completion/src/completions')
-rw-r--r--crates/ide_completion/src/completions/flyimport.rs3
-rw-r--r--crates/ide_completion/src/completions/keyword.rs39
-rw-r--r--crates/ide_completion/src/completions/snippet.rs2
-rw-r--r--crates/ide_completion/src/completions/unqualified_path.rs3
4 files changed, 21 insertions, 26 deletions
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs
index 9d5b61562..b7d3ee8ce 100644
--- a/crates/ide_completion/src/completions/flyimport.rs
+++ b/crates/ide_completion/src/completions/flyimport.rs
@@ -114,8 +114,7 @@ pub(crate) fn import_on_the_fly(acc: &mut Completions, ctx: &CompletionContext)
114 || ctx.attribute_under_caret.is_some() 114 || ctx.attribute_under_caret.is_some()
115 || ctx.mod_declaration_under_caret.is_some() 115 || ctx.mod_declaration_under_caret.is_some()
116 || ctx.record_lit_syntax.is_some() 116 || ctx.record_lit_syntax.is_some()
117 || ctx.has_trait_parent 117 || ctx.has_impl_or_trait_parent()
118 || ctx.has_impl_parent
119 { 118 {
120 return None; 119 return None;
121 } 120 }
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs
index fa6bcc955..58e35bad9 100644
--- a/crates/ide_completion/src/completions/keyword.rs
+++ b/crates/ide_completion/src/completions/keyword.rs
@@ -49,34 +49,35 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
49 return; 49 return;
50 } 50 }
51 51
52 let has_trait_or_impl_parent = ctx.has_impl_parent || ctx.has_trait_parent; 52 let has_trait_or_impl_parent = ctx.has_impl_or_trait_parent();
53 if ctx.trait_as_prev_sibling || ctx.impl_as_prev_sibling { 53 let has_block_expr_parent = ctx.has_block_expr_parent();
54 let has_item_list_parent = ctx.has_item_list_parent();
55 if ctx.has_impl_or_trait_prev_sibling() {
54 add_keyword(ctx, acc, "where", "where "); 56 add_keyword(ctx, acc, "where", "where ");
55 return; 57 return;
56 } 58 }
57 if ctx.previous_token_is(T![unsafe]) { 59 if ctx.previous_token_is(T![unsafe]) {
58 if ctx.has_item_list_or_source_file_parent || ctx.block_expr_parent { 60 if has_item_list_parent || has_block_expr_parent {
59 add_keyword(ctx, acc, "fn", "fn $1($2) {\n $0\n}") 61 add_keyword(ctx, acc, "fn", "fn $1($2) {\n $0\n}")
60 } 62 }
61 63
62 if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { 64 if has_item_list_parent || has_block_expr_parent {
63 add_keyword(ctx, acc, "trait", "trait $1 {\n $0\n}"); 65 add_keyword(ctx, acc, "trait", "trait $1 {\n $0\n}");
64 add_keyword(ctx, acc, "impl", "impl $1 {\n $0\n}"); 66 add_keyword(ctx, acc, "impl", "impl $1 {\n $0\n}");
65 } 67 }
66 68
67 return; 69 return;
68 } 70 }
69 if ctx.has_item_list_or_source_file_parent || has_trait_or_impl_parent || ctx.block_expr_parent 71 if has_item_list_parent || has_trait_or_impl_parent || has_block_expr_parent {
70 {
71 add_keyword(ctx, acc, "fn", "fn $1($2) {\n $0\n}"); 72 add_keyword(ctx, acc, "fn", "fn $1($2) {\n $0\n}");
72 } 73 }
73 if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { 74 if has_item_list_parent || has_block_expr_parent {
74 add_keyword(ctx, acc, "use", "use "); 75 add_keyword(ctx, acc, "use", "use ");
75 add_keyword(ctx, acc, "impl", "impl $1 {\n $0\n}"); 76 add_keyword(ctx, acc, "impl", "impl $1 {\n $0\n}");
76 add_keyword(ctx, acc, "trait", "trait $1 {\n $0\n}"); 77 add_keyword(ctx, acc, "trait", "trait $1 {\n $0\n}");
77 } 78 }
78 79
79 if ctx.has_item_list_or_source_file_parent { 80 if has_item_list_parent {
80 add_keyword(ctx, acc, "enum", "enum $1 {\n $0\n}"); 81 add_keyword(ctx, acc, "enum", "enum $1 {\n $0\n}");
81 add_keyword(ctx, acc, "struct", "struct $0"); 82 add_keyword(ctx, acc, "struct", "struct $0");
82 add_keyword(ctx, acc, "union", "union $1 {\n $0\n}"); 83 add_keyword(ctx, acc, "union", "union $1 {\n $0\n}");
@@ -92,7 +93,7 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
92 add_keyword(ctx, acc, "for", "for $1 in $2 {\n $0\n}"); 93 add_keyword(ctx, acc, "for", "for $1 in $2 {\n $0\n}");
93 } 94 }
94 95
95 if ctx.previous_token_is(T![if]) || ctx.previous_token_is(T![while]) || ctx.block_expr_parent { 96 if ctx.previous_token_is(T![if]) || ctx.previous_token_is(T![while]) || has_block_expr_parent {
96 add_keyword(ctx, acc, "let", "let "); 97 add_keyword(ctx, acc, "let", "let ");
97 } 98 }
98 99
@@ -100,27 +101,23 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
100 add_keyword(ctx, acc, "else", "else {\n $0\n}"); 101 add_keyword(ctx, acc, "else", "else {\n $0\n}");
101 add_keyword(ctx, acc, "else if", "else if $1 {\n $0\n}"); 102 add_keyword(ctx, acc, "else if", "else if $1 {\n $0\n}");
102 } 103 }
103 if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { 104 if has_item_list_parent || has_block_expr_parent {
104 add_keyword(ctx, acc, "mod", "mod $0"); 105 add_keyword(ctx, acc, "mod", "mod $0");
105 } 106 }
106 if ctx.bind_pat_parent || ctx.ref_pat_parent { 107 if ctx.has_ident_or_ref_pat_parent() {
107 add_keyword(ctx, acc, "mut", "mut "); 108 add_keyword(ctx, acc, "mut", "mut ");
108 } 109 }
109 if ctx.has_item_list_or_source_file_parent || has_trait_or_impl_parent || ctx.block_expr_parent 110 if has_item_list_parent || has_trait_or_impl_parent || has_block_expr_parent {
110 {
111 add_keyword(ctx, acc, "const", "const "); 111 add_keyword(ctx, acc, "const", "const ");
112 add_keyword(ctx, acc, "type", "type "); 112 add_keyword(ctx, acc, "type", "type ");
113 } 113 }
114 if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { 114 if has_item_list_parent || has_block_expr_parent {
115 add_keyword(ctx, acc, "static", "static "); 115 add_keyword(ctx, acc, "static", "static ");
116 }; 116 };
117 if (ctx.has_item_list_or_source_file_parent) || ctx.block_expr_parent { 117 if has_item_list_parent || has_block_expr_parent {
118 add_keyword(ctx, acc, "extern", "extern "); 118 add_keyword(ctx, acc, "extern", "extern ");
119 } 119 }
120 if ctx.has_item_list_or_source_file_parent 120 if has_item_list_parent || has_trait_or_impl_parent || has_block_expr_parent || ctx.is_match_arm
121 || has_trait_or_impl_parent
122 || ctx.block_expr_parent
123 || ctx.is_match_arm
124 { 121 {
125 add_keyword(ctx, acc, "unsafe", "unsafe "); 122 add_keyword(ctx, acc, "unsafe", "unsafe ");
126 } 123 }
@@ -133,7 +130,7 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
133 add_keyword(ctx, acc, "break", "break"); 130 add_keyword(ctx, acc, "break", "break");
134 } 131 }
135 } 132 }
136 if ctx.has_item_list_or_source_file_parent || ctx.has_impl_parent | ctx.has_field_list_parent { 133 if has_item_list_parent || ctx.has_impl_parent() || ctx.has_field_list_parent() {
137 add_keyword(ctx, acc, "pub(crate)", "pub(crate) "); 134 add_keyword(ctx, acc, "pub(crate)", "pub(crate) ");
138 add_keyword(ctx, acc, "pub", "pub "); 135 add_keyword(ctx, acc, "pub", "pub ");
139 } 136 }
@@ -141,7 +138,7 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte
141 if !ctx.is_trivial_path { 138 if !ctx.is_trivial_path {
142 return; 139 return;
143 } 140 }
144 let fn_def = match &ctx.function_syntax { 141 let fn_def = match &ctx.function_def {
145 Some(it) => it, 142 Some(it) => it,
146 None => return, 143 None => return,
147 }; 144 };
diff --git a/crates/ide_completion/src/completions/snippet.rs b/crates/ide_completion/src/completions/snippet.rs
index 14cfb61de..defc25b00 100644
--- a/crates/ide_completion/src/completions/snippet.rs
+++ b/crates/ide_completion/src/completions/snippet.rs
@@ -14,7 +14,7 @@ fn snippet(ctx: &CompletionContext, cap: SnippetCap, label: &str, snippet: &str)
14} 14}
15 15
16pub(crate) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) { 16pub(crate) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) {
17 if !(ctx.is_trivial_path && ctx.function_syntax.is_some()) { 17 if !(ctx.is_trivial_path && ctx.function_def.is_some()) {
18 return; 18 return;
19 } 19 }
20 let cap = match ctx.config.snippet_cap { 20 let cap = match ctx.config.snippet_cap {
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs
index b8f8ef25f..7496d26c4 100644
--- a/crates/ide_completion/src/completions/unqualified_path.rs
+++ b/crates/ide_completion/src/completions/unqualified_path.rs
@@ -13,8 +13,7 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
13 || ctx.record_pat_syntax.is_some() 13 || ctx.record_pat_syntax.is_some()
14 || ctx.attribute_under_caret.is_some() 14 || ctx.attribute_under_caret.is_some()
15 || ctx.mod_declaration_under_caret.is_some() 15 || ctx.mod_declaration_under_caret.is_some()
16 || ctx.has_impl_parent 16 || ctx.has_impl_or_trait_parent()
17 || ctx.has_trait_parent
18 { 17 {
19 return; 18 return;
20 } 19 }