@@ -56,10 +56,16 @@ impl Builder {
5656}
5757
5858impl Completions {
59- pub ( crate ) fn add ( & mut self , item : CompletionItem ) {
59+ fn add ( & mut self , item : CompletionItem ) {
6060 self . buf . push ( item)
6161 }
6262
63+ fn add_opt ( & mut self , item : Option < CompletionItem > ) {
64+ if let Some ( item) = item {
65+ self . buf . push ( item)
66+ }
67+ }
68+
6369 pub ( crate ) fn add_all < I > ( & mut self , items : I )
6470 where
6571 I : IntoIterator ,
@@ -103,9 +109,10 @@ impl Completions {
103109 local_name : hir:: Name ,
104110 resolution : & hir:: ScopeDef ,
105111 ) {
106- if let Some ( item ) = render_resolution ( RenderContext :: new ( ctx ) , local_name , resolution) {
107- self . add ( item ) ;
112+ if ctx . expects_type ( ) && resolution. is_value_def ( ) {
113+ return ;
108114 }
115+ self . add_opt ( render_resolution ( RenderContext :: new ( ctx) , local_name, resolution) ) ;
109116 }
110117
111118 pub ( crate ) fn add_macro (
@@ -118,9 +125,7 @@ impl Completions {
118125 Some ( it) => it,
119126 None => return ,
120127 } ;
121- if let Some ( item) = render_macro ( RenderContext :: new ( ctx) , None , name, macro_) {
122- self . add ( item) ;
123- }
128+ self . add_opt ( render_macro ( RenderContext :: new ( ctx) , None , name, macro_) ) ;
124129 }
125130
126131 pub ( crate ) fn add_function (
@@ -129,9 +134,10 @@ impl Completions {
129134 func : hir:: Function ,
130135 local_name : Option < hir:: Name > ,
131136 ) {
132- if let Some ( item ) = render_fn ( RenderContext :: new ( ctx) , None , local_name , func ) {
133- self . add ( item )
137+ if ctx. expects_type ( ) {
138+ return ;
134139 }
140+ self . add_opt ( render_fn ( RenderContext :: new ( ctx) , None , local_name, func) ) ;
135141 }
136142
137143 pub ( crate ) fn add_method (
@@ -141,10 +147,7 @@ impl Completions {
141147 receiver : Option < hir:: Name > ,
142148 local_name : Option < hir:: Name > ,
143149 ) {
144- if let Some ( item) = render_method ( RenderContext :: new ( ctx) , None , receiver, local_name, func)
145- {
146- self . add ( item)
147- }
150+ self . add_opt ( render_method ( RenderContext :: new ( ctx) , None , receiver, local_name, func) ) ;
148151 }
149152
150153 pub ( crate ) fn add_variant_pat (
@@ -153,9 +156,7 @@ impl Completions {
153156 variant : hir:: Variant ,
154157 local_name : Option < hir:: Name > ,
155158 ) {
156- if let Some ( item) = render_variant_pat ( RenderContext :: new ( ctx) , variant, local_name, None ) {
157- self . add ( item) ;
158- }
159+ self . add_opt ( render_variant_pat ( RenderContext :: new ( ctx) , variant, local_name, None ) ) ;
159160 }
160161
161162 pub ( crate ) fn add_qualified_variant_pat (
@@ -164,9 +165,7 @@ impl Completions {
164165 variant : hir:: Variant ,
165166 path : hir:: ModPath ,
166167 ) {
167- if let Some ( item) = render_variant_pat ( RenderContext :: new ( ctx) , variant, None , Some ( path) ) {
168- self . add ( item) ;
169- }
168+ self . add_opt ( render_variant_pat ( RenderContext :: new ( ctx) , variant, None , Some ( path) ) ) ;
170169 }
171170
172171 pub ( crate ) fn add_struct_pat (
@@ -175,21 +174,18 @@ impl Completions {
175174 strukt : hir:: Struct ,
176175 local_name : Option < hir:: Name > ,
177176 ) {
178- if let Some ( item) = render_struct_pat ( RenderContext :: new ( ctx) , strukt, local_name) {
179- self . add ( item) ;
180- }
177+ self . add_opt ( render_struct_pat ( RenderContext :: new ( ctx) , strukt, local_name) ) ;
181178 }
182179
183180 pub ( crate ) fn add_const ( & mut self , ctx : & CompletionContext , constant : hir:: Const ) {
184- if let Some ( item ) = render_const ( RenderContext :: new ( ctx) , constant ) {
185- self . add ( item ) ;
181+ if ctx. expects_type ( ) {
182+ return ;
186183 }
184+ self . add_opt ( render_const ( RenderContext :: new ( ctx) , constant) ) ;
187185 }
188186
189187 pub ( crate ) fn add_type_alias ( & mut self , ctx : & CompletionContext , type_alias : hir:: TypeAlias ) {
190- if let Some ( item) = render_type_alias ( RenderContext :: new ( ctx) , type_alias) {
191- self . add ( item)
192- }
188+ self . add_opt ( render_type_alias ( RenderContext :: new ( ctx) , type_alias) ) ;
193189 }
194190
195191 pub ( crate ) fn add_qualified_enum_variant (
@@ -208,6 +204,9 @@ impl Completions {
208204 variant : hir:: Variant ,
209205 local_name : Option < hir:: Name > ,
210206 ) {
207+ if ctx. expects_type ( ) {
208+ return ;
209+ }
211210 let item = render_variant ( RenderContext :: new ( ctx) , None , local_name, variant, None ) ;
212211 self . add ( item) ;
213212 }
0 commit comments