@@ -23,13 +23,13 @@ pub(crate) mod vis;
23
23
use std:: iter;
24
24
25
25
use hir:: { known, ScopeDef } ;
26
- use ide_db:: SymbolKind ;
26
+ use ide_db:: { imports :: import_assets :: LocatedImport , SymbolKind } ;
27
27
use syntax:: ast;
28
28
29
29
use crate :: {
30
30
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 ,
33
33
} ,
34
34
item:: Builder ,
35
35
render:: {
@@ -38,7 +38,7 @@ use crate::{
38
38
literal:: { render_struct_literal, render_variant_lit} ,
39
39
macro_:: render_macro,
40
40
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,
42
42
type_alias:: { render_type_alias, render_type_alias_with_eq} ,
43
43
union_literal:: render_union_literal,
44
44
RenderContext ,
@@ -137,23 +137,27 @@ impl Completions {
137
137
pub ( crate ) fn add_crate_roots ( & mut self , ctx : & CompletionContext ) {
138
138
ctx. process_all_names ( & mut |name, res| match res {
139
139
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 ) ;
141
141
}
142
142
_ => ( ) ,
143
143
} ) ;
144
144
}
145
145
146
- pub ( crate ) fn add_resolution (
146
+ pub ( crate ) fn add_path_resolution (
147
147
& mut self ,
148
148
ctx : & CompletionContext ,
149
+ path_ctx : & PathCompletionCtx ,
149
150
local_name : hir:: Name ,
150
151
resolution : hir:: ScopeDef ,
151
152
) {
152
153
if ctx. is_scope_def_hidden ( resolution) {
153
154
cov_mark:: hit!( qualified_path_doc_hidden) ;
154
155
return ;
155
156
}
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
+ ) ;
157
161
}
158
162
159
163
pub ( crate ) fn add_resolution_simple (
@@ -174,12 +178,13 @@ impl Completions {
174
178
module : hir:: Module ,
175
179
local_name : hir:: Name ,
176
180
) {
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 ( ) ) ) ;
178
182
}
179
183
180
184
pub ( crate ) fn add_macro (
181
185
& mut self ,
182
186
ctx : & CompletionContext ,
187
+ path_ctx : & PathCompletionCtx ,
183
188
mac : hir:: Macro ,
184
189
local_name : hir:: Name ,
185
190
) {
@@ -191,6 +196,7 @@ impl Completions {
191
196
self . add (
192
197
render_macro (
193
198
RenderContext :: new ( ctx) . private_editable ( is_private_editable) ,
199
+ path_ctx,
194
200
local_name,
195
201
mac,
196
202
)
@@ -201,6 +207,7 @@ impl Completions {
201
207
pub ( crate ) fn add_function (
202
208
& mut self ,
203
209
ctx : & CompletionContext ,
210
+ path_ctx : & PathCompletionCtx ,
204
211
func : hir:: Function ,
205
212
local_name : Option < hir:: Name > ,
206
213
) {
@@ -212,6 +219,7 @@ impl Completions {
212
219
self . add (
213
220
render_fn (
214
221
RenderContext :: new ( ctx) . private_editable ( is_private_editable) ,
222
+ path_ctx,
215
223
local_name,
216
224
func,
217
225
)
@@ -222,6 +230,7 @@ impl Completions {
222
230
pub ( crate ) fn add_method (
223
231
& mut self ,
224
232
ctx : & CompletionContext ,
233
+ dot_access : & DotAccess ,
225
234
func : hir:: Function ,
226
235
receiver : Option < hir:: Name > ,
227
236
local_name : Option < hir:: Name > ,
@@ -234,6 +243,7 @@ impl Completions {
234
243
self . add (
235
244
render_method (
236
245
RenderContext :: new ( ctx) . private_editable ( is_private_editable) ,
246
+ dot_access,
237
247
receiver,
238
248
local_name,
239
249
func,
@@ -242,6 +252,32 @@ impl Completions {
242
252
) ;
243
253
}
244
254
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
+
245
281
pub ( crate ) fn add_const ( & mut self , ctx : & CompletionContext , konst : hir:: Const ) {
246
282
let is_private_editable = match ctx. is_visible ( & konst) {
247
283
Visible :: Yes => false ,
@@ -277,11 +313,12 @@ impl Completions {
277
313
pub ( crate ) fn add_qualified_enum_variant (
278
314
& mut self ,
279
315
ctx : & CompletionContext ,
316
+ path_ctx : & PathCompletionCtx ,
280
317
variant : hir:: Variant ,
281
318
path : hir:: ModPath ,
282
319
) {
283
320
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) )
285
322
{
286
323
self . add ( builder. build ( ) ) ;
287
324
}
@@ -290,11 +327,12 @@ impl Completions {
290
327
pub ( crate ) fn add_enum_variant (
291
328
& mut self ,
292
329
ctx : & CompletionContext ,
330
+ path_ctx : & PathCompletionCtx ,
293
331
variant : hir:: Variant ,
294
332
local_name : Option < hir:: Name > ,
295
333
) {
296
334
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 )
298
336
{
299
337
self . add ( builder. build ( ) ) ;
300
338
}
@@ -324,12 +362,13 @@ impl Completions {
324
362
pub ( crate ) fn add_struct_literal (
325
363
& mut self ,
326
364
ctx : & CompletionContext ,
365
+ path_ctx : & PathCompletionCtx ,
327
366
strukt : hir:: Struct ,
328
367
path : Option < hir:: ModPath > ,
329
368
local_name : Option < hir:: Name > ,
330
369
) {
331
370
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)
333
372
{
334
373
self . add ( builder. build ( ) ) ;
335
374
}
@@ -369,11 +408,13 @@ impl Completions {
369
408
pub ( crate ) fn add_variant_pat (
370
409
& mut self ,
371
410
ctx : & CompletionContext ,
411
+ pattern_ctx : & PatternContext ,
372
412
variant : hir:: Variant ,
373
413
local_name : Option < hir:: Name > ,
374
414
) {
375
415
self . add_opt ( render_variant_pat (
376
416
RenderContext :: new ( ctx) ,
417
+ pattern_ctx,
377
418
variant,
378
419
local_name. clone ( ) ,
379
420
None ,
@@ -383,20 +424,22 @@ impl Completions {
383
424
pub ( crate ) fn add_qualified_variant_pat (
384
425
& mut self ,
385
426
ctx : & CompletionContext ,
427
+ pattern_ctx : & PatternContext ,
386
428
variant : hir:: Variant ,
387
429
path : hir:: ModPath ,
388
430
) {
389
431
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) ) ;
391
433
}
392
434
393
435
pub ( crate ) fn add_struct_pat (
394
436
& mut self ,
395
437
ctx : & CompletionContext ,
438
+ pattern_ctx : & PatternContext ,
396
439
strukt : hir:: Struct ,
397
440
local_name : Option < hir:: Name > ,
398
441
) {
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) ) ;
400
443
}
401
444
}
402
445
0 commit comments