@@ -34,7 +34,7 @@ use crate::{
3434 CompletionContext , CompletionItem , CompletionItemKind ,
3535 context:: {
3636 DotAccess , ItemListKind , NameContext , NameKind , NameRefContext , NameRefKind ,
37- PathCompletionCtx , PathKind , PatternContext , TypeLocation , Visible ,
37+ PathCompletionCtx , PathKind , PatternContext , TypeAscriptionTarget , TypeLocation , Visible ,
3838 } ,
3939 item:: Builder ,
4040 render:: {
@@ -45,7 +45,7 @@ use crate::{
4545 macro_:: render_macro,
4646 pattern:: { render_struct_pat, render_variant_pat} ,
4747 render_expr, render_field, render_path_resolution, render_pattern_resolution,
48- render_tuple_field,
48+ render_tuple_field, render_type_keyword_snippet ,
4949 type_alias:: { render_type_alias, render_type_alias_with_eq} ,
5050 union_literal:: render_union_literal,
5151 } ,
@@ -104,6 +104,21 @@ impl Completions {
104104 }
105105 }
106106
107+ pub ( crate ) fn add_nameref_keywords_with_type_like (
108+ & mut self ,
109+ ctx : & CompletionContext < ' _ > ,
110+ path_ctx : & PathCompletionCtx < ' _ > ,
111+ ) {
112+ let mut add_keyword = |kw| {
113+ render_type_keyword_snippet ( ctx, path_ctx, kw, kw) . add_to ( self , ctx. db ) ;
114+ } ;
115+ [ "self::" , "crate::" ] . into_iter ( ) . for_each ( & mut add_keyword) ;
116+
117+ if ctx. depth_from_crate_root > 0 {
118+ add_keyword ( "super::" ) ;
119+ }
120+ }
121+
107122 pub ( crate ) fn add_nameref_keywords ( & mut self , ctx : & CompletionContext < ' _ > ) {
108123 [ "self" , "crate" ] . into_iter ( ) . for_each ( |kw| self . add_keyword ( ctx, kw) ) ;
109124
@@ -112,11 +127,19 @@ impl Completions {
112127 }
113128 }
114129
115- pub ( crate ) fn add_type_keywords ( & mut self , ctx : & CompletionContext < ' _ > ) {
116- self . add_keyword_snippet ( ctx, "fn" , "fn($1)" ) ;
117- self . add_keyword_snippet ( ctx, "dyn" , "dyn $0" ) ;
118- self . add_keyword_snippet ( ctx, "impl" , "impl $0" ) ;
119- self . add_keyword_snippet ( ctx, "for" , "for<$1>" ) ;
130+ pub ( crate ) fn add_type_keywords (
131+ & mut self ,
132+ ctx : & CompletionContext < ' _ > ,
133+ path_ctx : & PathCompletionCtx < ' _ > ,
134+ ) {
135+ let mut add_keyword = |kw, snippet| {
136+ render_type_keyword_snippet ( ctx, path_ctx, kw, snippet) . add_to ( self , ctx. db ) ;
137+ } ;
138+
139+ add_keyword ( "fn" , "fn($1)" ) ;
140+ add_keyword ( "dyn" , "dyn $0" ) ;
141+ add_keyword ( "impl" , "impl $0" ) ;
142+ add_keyword ( "for" , "for<$1>" ) ;
120143 }
121144
122145 pub ( crate ) fn add_super_keyword (
@@ -747,6 +770,12 @@ pub(super) fn complete_name_ref(
747770 field:: complete_field_list_tuple_variant ( acc, ctx, path_ctx) ;
748771 }
749772 TypeLocation :: TypeAscription ( ascription) => {
773+ if let TypeAscriptionTarget :: RetType { item : Some ( item) , .. } =
774+ ascription
775+ && path_ctx. required_thin_arrow ( ) . is_some ( )
776+ {
777+ keyword:: complete_for_and_where ( acc, ctx, & item. clone ( ) . into ( ) ) ;
778+ }
750779 r#type:: complete_ascribed_type ( acc, ctx, path_ctx, ascription) ;
751780 }
752781 TypeLocation :: GenericArg { .. }
0 commit comments