@@ -23,13 +23,13 @@ pub(crate) mod vis;
2323use std:: iter;
2424
2525use hir:: { known, ScopeDef } ;
26- use ide_db:: SymbolKind ;
26+ use ide_db:: { imports :: import_assets :: LocatedImport , SymbolKind } ;
2727use syntax:: ast;
2828
2929use crate :: {
3030 context:: {
31- ItemListKind , NameContext , NameKind , NameRefContext , NameRefKind , PathKind , PatternContext ,
32- TypeLocation , Visible ,
31+ DotAccess , ItemListKind , NameContext , NameKind , NameRefContext , NameRefKind ,
32+ PathCompletionCtx , PathKind , PatternContext , TypeLocation , Visible ,
3333 } ,
3434 item:: Builder ,
3535 render:: {
@@ -38,7 +38,7 @@ use crate::{
3838 literal:: { render_struct_literal, render_variant_lit} ,
3939 macro_:: render_macro,
4040 pattern:: { render_struct_pat, render_variant_pat} ,
41- render_field, render_resolution , render_resolution_simple, render_tuple_field,
41+ render_field, render_path_resolution , render_resolution_simple, render_tuple_field,
4242 type_alias:: { render_type_alias, render_type_alias_with_eq} ,
4343 union_literal:: render_union_literal,
4444 RenderContext ,
@@ -137,23 +137,27 @@ impl Completions {
137137 pub ( crate ) fn add_crate_roots ( & mut self , ctx : & CompletionContext ) {
138138 ctx. process_all_names ( & mut |name, res| match res {
139139 ScopeDef :: ModuleDef ( hir:: ModuleDef :: Module ( m) ) if m. is_crate_root ( ctx. db ) => {
140- self . add_resolution ( ctx, name , res ) ;
140+ self . add_module ( ctx, m , name ) ;
141141 }
142142 _ => ( ) ,
143143 } ) ;
144144 }
145145
146- pub ( crate ) fn add_resolution (
146+ pub ( crate ) fn add_path_resolution (
147147 & mut self ,
148148 ctx : & CompletionContext ,
149+ path_ctx : & PathCompletionCtx ,
149150 local_name : hir:: Name ,
150151 resolution : hir:: ScopeDef ,
151152 ) {
152153 if ctx. is_scope_def_hidden ( resolution) {
153154 cov_mark:: hit!( qualified_path_doc_hidden) ;
154155 return ;
155156 }
156- self . add ( render_resolution ( RenderContext :: new ( ctx) , local_name, resolution) . build ( ) ) ;
157+ self . add (
158+ render_path_resolution ( RenderContext :: new ( ctx) , path_ctx, local_name, resolution)
159+ . build ( ) ,
160+ ) ;
157161 }
158162
159163 pub ( crate ) fn add_resolution_simple (
@@ -174,12 +178,13 @@ impl Completions {
174178 module : hir:: Module ,
175179 local_name : hir:: Name ,
176180 ) {
177- self . add_resolution ( ctx, local_name, hir:: ScopeDef :: ModuleDef ( module. into ( ) ) ) ;
181+ self . add_resolution_simple ( ctx, local_name, hir:: ScopeDef :: ModuleDef ( module. into ( ) ) ) ;
178182 }
179183
180184 pub ( crate ) fn add_macro (
181185 & mut self ,
182186 ctx : & CompletionContext ,
187+ path_ctx : & PathCompletionCtx ,
183188 mac : hir:: Macro ,
184189 local_name : hir:: Name ,
185190 ) {
@@ -191,6 +196,7 @@ impl Completions {
191196 self . add (
192197 render_macro (
193198 RenderContext :: new ( ctx) . private_editable ( is_private_editable) ,
199+ path_ctx,
194200 local_name,
195201 mac,
196202 )
@@ -201,6 +207,7 @@ impl Completions {
201207 pub ( crate ) fn add_function (
202208 & mut self ,
203209 ctx : & CompletionContext ,
210+ path_ctx : & PathCompletionCtx ,
204211 func : hir:: Function ,
205212 local_name : Option < hir:: Name > ,
206213 ) {
@@ -212,6 +219,7 @@ impl Completions {
212219 self . add (
213220 render_fn (
214221 RenderContext :: new ( ctx) . private_editable ( is_private_editable) ,
222+ path_ctx,
215223 local_name,
216224 func,
217225 )
@@ -222,6 +230,7 @@ impl Completions {
222230 pub ( crate ) fn add_method (
223231 & mut self ,
224232 ctx : & CompletionContext ,
233+ dot_access : & DotAccess ,
225234 func : hir:: Function ,
226235 receiver : Option < hir:: Name > ,
227236 local_name : Option < hir:: Name > ,
@@ -234,6 +243,7 @@ impl Completions {
234243 self . add (
235244 render_method (
236245 RenderContext :: new ( ctx) . private_editable ( is_private_editable) ,
246+ dot_access,
237247 receiver,
238248 local_name,
239249 func,
@@ -242,6 +252,32 @@ impl Completions {
242252 ) ;
243253 }
244254
255+ pub ( crate ) fn add_method_with_import (
256+ & mut self ,
257+ ctx : & CompletionContext ,
258+ dot_access : & DotAccess ,
259+ func : hir:: Function ,
260+ import : LocatedImport ,
261+ ) {
262+ let is_private_editable = match ctx. is_visible ( & func) {
263+ Visible :: Yes => false ,
264+ Visible :: Editable => true ,
265+ Visible :: No => return ,
266+ } ;
267+ self . add (
268+ render_method (
269+ RenderContext :: new ( ctx)
270+ . private_editable ( is_private_editable)
271+ . import_to_add ( Some ( import) ) ,
272+ dot_access,
273+ None ,
274+ None ,
275+ func,
276+ )
277+ . build ( ) ,
278+ ) ;
279+ }
280+
245281 pub ( crate ) fn add_const ( & mut self , ctx : & CompletionContext , konst : hir:: Const ) {
246282 let is_private_editable = match ctx. is_visible ( & konst) {
247283 Visible :: Yes => false ,
@@ -277,11 +313,12 @@ impl Completions {
277313 pub ( crate ) fn add_qualified_enum_variant (
278314 & mut self ,
279315 ctx : & CompletionContext ,
316+ path_ctx : & PathCompletionCtx ,
280317 variant : hir:: Variant ,
281318 path : hir:: ModPath ,
282319 ) {
283320 if let Some ( builder) =
284- render_variant_lit ( RenderContext :: new ( ctx) , None , variant, Some ( path) )
321+ render_variant_lit ( RenderContext :: new ( ctx) , path_ctx , None , variant, Some ( path) )
285322 {
286323 self . add ( builder. build ( ) ) ;
287324 }
@@ -290,11 +327,12 @@ impl Completions {
290327 pub ( crate ) fn add_enum_variant (
291328 & mut self ,
292329 ctx : & CompletionContext ,
330+ path_ctx : & PathCompletionCtx ,
293331 variant : hir:: Variant ,
294332 local_name : Option < hir:: Name > ,
295333 ) {
296334 if let Some ( builder) =
297- render_variant_lit ( RenderContext :: new ( ctx) , local_name, variant, None )
335+ render_variant_lit ( RenderContext :: new ( ctx) , path_ctx , local_name, variant, None )
298336 {
299337 self . add ( builder. build ( ) ) ;
300338 }
@@ -324,12 +362,13 @@ impl Completions {
324362 pub ( crate ) fn add_struct_literal (
325363 & mut self ,
326364 ctx : & CompletionContext ,
365+ path_ctx : & PathCompletionCtx ,
327366 strukt : hir:: Struct ,
328367 path : Option < hir:: ModPath > ,
329368 local_name : Option < hir:: Name > ,
330369 ) {
331370 if let Some ( builder) =
332- render_struct_literal ( RenderContext :: new ( ctx) , strukt, path, local_name)
371+ render_struct_literal ( RenderContext :: new ( ctx) , path_ctx , strukt, path, local_name)
333372 {
334373 self . add ( builder. build ( ) ) ;
335374 }
@@ -369,11 +408,13 @@ impl Completions {
369408 pub ( crate ) fn add_variant_pat (
370409 & mut self ,
371410 ctx : & CompletionContext ,
411+ pattern_ctx : & PatternContext ,
372412 variant : hir:: Variant ,
373413 local_name : Option < hir:: Name > ,
374414 ) {
375415 self . add_opt ( render_variant_pat (
376416 RenderContext :: new ( ctx) ,
417+ pattern_ctx,
377418 variant,
378419 local_name. clone ( ) ,
379420 None ,
@@ -383,20 +424,22 @@ impl Completions {
383424 pub ( crate ) fn add_qualified_variant_pat (
384425 & mut self ,
385426 ctx : & CompletionContext ,
427+ pattern_ctx : & PatternContext ,
386428 variant : hir:: Variant ,
387429 path : hir:: ModPath ,
388430 ) {
389431 let path = Some ( & path) ;
390- self . add_opt ( render_variant_pat ( RenderContext :: new ( ctx) , variant, None , path) ) ;
432+ self . add_opt ( render_variant_pat ( RenderContext :: new ( ctx) , pattern_ctx , variant, None , path) ) ;
391433 }
392434
393435 pub ( crate ) fn add_struct_pat (
394436 & mut self ,
395437 ctx : & CompletionContext ,
438+ pattern_ctx : & PatternContext ,
396439 strukt : hir:: Struct ,
397440 local_name : Option < hir:: Name > ,
398441 ) {
399- self . add_opt ( render_struct_pat ( RenderContext :: new ( ctx) , strukt, local_name) ) ;
442+ self . add_opt ( render_struct_pat ( RenderContext :: new ( ctx) , pattern_ctx , strukt, local_name) ) ;
400443 }
401444}
402445
@@ -541,8 +584,8 @@ pub(super) fn complete_name_ref(
541584 NameRefKind :: Keyword ( item) => {
542585 keyword:: complete_for_and_where ( acc, ctx, item) ;
543586 }
544- NameRefKind :: RecordExpr ( record_expr ) => {
545- record:: complete_record_expr_fields ( acc, ctx, record_expr ) ;
587+ NameRefKind :: RecordExpr { dot_prefix , expr } => {
588+ record:: complete_record_expr_fields ( acc, ctx, expr , dot_prefix ) ;
546589 }
547590 NameRefKind :: Pattern ( pattern_ctx) => complete_patterns ( acc, ctx, pattern_ctx) ,
548591 }
0 commit comments