@@ -16,10 +16,10 @@ use crate::{
1616 call_info:: ActiveParameter ,
1717 completion:: {
1818 patterns:: {
19- has_bind_pat_parent , has_block_expr_parent , has_field_list_parent ,
20- has_impl_as_prev_sibling , has_impl_parent , has_item_list_or_source_file_parent ,
21- has_ref_parent , has_trait_as_prev_sibling , has_trait_parent , if_is_prev ,
22- is_in_loop_body, is_match_arm, unsafe_is_prev,
19+ fn_is_prev , for_is_prev2 , has_bind_pat_parent , has_block_expr_parent ,
20+ has_field_list_parent , has_impl_as_prev_sibling , has_impl_parent ,
21+ has_item_list_or_source_file_parent , has_ref_parent , has_trait_as_prev_sibling ,
22+ has_trait_parent , if_is_prev , is_in_loop_body, is_match_arm, unsafe_is_prev,
2323 } ,
2424 CompletionConfig ,
2525 } ,
@@ -91,6 +91,8 @@ pub(crate) struct CompletionContext<'a> {
9191 pub ( super ) impl_as_prev_sibling : bool ,
9292 pub ( super ) is_match_arm : bool ,
9393 pub ( super ) has_item_list_or_source_file_parent : bool ,
94+ pub ( super ) for_is_prev2 : bool ,
95+ pub ( super ) fn_is_prev : bool ,
9496 pub ( super ) locals : Vec < ( String , Local ) > ,
9597}
9698
@@ -174,6 +176,8 @@ impl<'a> CompletionContext<'a> {
174176 if_is_prev : false ,
175177 is_match_arm : false ,
176178 has_item_list_or_source_file_parent : false ,
179+ for_is_prev2 : false ,
180+ fn_is_prev : false ,
177181 locals,
178182 } ;
179183
@@ -221,6 +225,14 @@ impl<'a> CompletionContext<'a> {
221225 Some ( ctx)
222226 }
223227
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+
224236 /// The range of the identifier that is being completed.
225237 pub ( crate ) fn source_range ( & self ) -> TextRange {
226238 // check kind of macro-expanded token, but use range of original token
@@ -253,6 +265,8 @@ impl<'a> CompletionContext<'a> {
253265 self . mod_declaration_under_caret =
254266 find_node_at_offset :: < ast:: Module > ( & file_with_fake_ident, offset)
255267 . 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 ( ) ) ;
256270 }
257271
258272 fn fill (
0 commit comments