aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/completion/completion_context.rs
diff options
context:
space:
mode:
authorIgor Aleksanov <[email protected]>2020-10-12 08:59:15 +0100
committerIgor Aleksanov <[email protected]>2020-10-17 08:27:59 +0100
commit70157f07d9a33e4b8ed71e162218a793f44a7691 (patch)
tree26f9d4c06ac0428c0a35450dd305d9076b89e2fe /crates/ide/src/completion/completion_context.rs
parent59483c217662fc5d89ef9da1cb93760e14a48418 (diff)
Remove redundant completions
Diffstat (limited to 'crates/ide/src/completion/completion_context.rs')
-rw-r--r--crates/ide/src/completion/completion_context.rs22
1 files changed, 18 insertions, 4 deletions
diff --git a/crates/ide/src/completion/completion_context.rs b/crates/ide/src/completion/completion_context.rs
index 8dea8a4bf..c9473cca6 100644
--- a/crates/ide/src/completion/completion_context.rs
+++ b/crates/ide/src/completion/completion_context.rs
@@ -16,10 +16,10 @@ use crate::{
16 call_info::ActiveParameter, 16 call_info::ActiveParameter,
17 completion::{ 17 completion::{
18 patterns::{ 18 patterns::{
19 has_bind_pat_parent, has_block_expr_parent, has_field_list_parent, 19 fn_is_prev, for_is_prev2, has_bind_pat_parent, has_block_expr_parent,
20 has_impl_as_prev_sibling, has_impl_parent, has_item_list_or_source_file_parent, 20 has_field_list_parent, has_impl_as_prev_sibling, has_impl_parent,
21 has_ref_parent, has_trait_as_prev_sibling, has_trait_parent, if_is_prev, 21 has_item_list_or_source_file_parent, has_ref_parent, has_trait_as_prev_sibling,
22 is_in_loop_body, is_match_arm, unsafe_is_prev, 22 has_trait_parent, if_is_prev, is_in_loop_body, is_match_arm, unsafe_is_prev,
23 }, 23 },
24 CompletionConfig, 24 CompletionConfig,
25 }, 25 },
@@ -91,6 +91,8 @@ pub(crate) struct CompletionContext<'a> {
91 pub(super) impl_as_prev_sibling: bool, 91 pub(super) impl_as_prev_sibling: bool,
92 pub(super) is_match_arm: bool, 92 pub(super) is_match_arm: bool,
93 pub(super) has_item_list_or_source_file_parent: bool, 93 pub(super) has_item_list_or_source_file_parent: bool,
94 pub(super) for_is_prev2: bool,
95 pub(super) fn_is_prev: bool,
94 pub(super) locals: Vec<(String, Local)>, 96 pub(super) locals: Vec<(String, Local)>,
95} 97}
96 98
@@ -174,6 +176,8 @@ impl<'a> CompletionContext<'a> {
174 if_is_prev: false, 176 if_is_prev: false,
175 is_match_arm: false, 177 is_match_arm: false,
176 has_item_list_or_source_file_parent: false, 178 has_item_list_or_source_file_parent: false,
179 for_is_prev2: false,
180 fn_is_prev: false,
177 locals, 181 locals,
178 }; 182 };
179 183
@@ -221,6 +225,14 @@ impl<'a> CompletionContext<'a> {
221 Some(ctx) 225 Some(ctx)
222 } 226 }
223 227
228 /// Checks whether completions in that particular case don't make much sense.
229 /// Examples:
230 /// - `fn <|>` -- we expect function name, it's unlikely that "hint" will be helpful.
231 /// - `for _ i<|>` -- obviously, it'll be "in" keyword.
232 pub(crate) fn no_completion_required(&self) -> bool {
233 self.fn_is_prev || self.for_is_prev2
234 }
235
224 /// The range of the identifier that is being completed. 236 /// The range of the identifier that is being completed.
225 pub(crate) fn source_range(&self) -> TextRange { 237 pub(crate) fn source_range(&self) -> TextRange {
226 // check kind of macro-expanded token, but use range of original token 238 // check kind of macro-expanded token, but use range of original token
@@ -253,6 +265,8 @@ impl<'a> CompletionContext<'a> {
253 self.mod_declaration_under_caret = 265 self.mod_declaration_under_caret =
254 find_node_at_offset::<ast::Module>(&file_with_fake_ident, offset) 266 find_node_at_offset::<ast::Module>(&file_with_fake_ident, offset)
255 .filter(|module| module.item_list().is_none()); 267 .filter(|module| module.item_list().is_none());
268 self.for_is_prev2 = for_is_prev2(syntax_element.clone());
269 self.fn_is_prev = fn_is_prev(syntax_element.clone());
256 } 270 }
257 271
258 fn fill( 272 fn fill(