diff options
Diffstat (limited to 'crates/completion')
-rw-r--r-- | crates/completion/src/completions.rs | 10 | ||||
-rw-r--r-- | crates/completion/src/completions/attribute.rs | 16 | ||||
-rw-r--r-- | crates/completion/src/completions/dot.rs | 8 | ||||
-rw-r--r-- | crates/completion/src/completions/keyword.rs | 142 | ||||
-rw-r--r-- | crates/completion/src/completions/mod_.rs | 4 | ||||
-rw-r--r-- | crates/completion/src/completions/pattern.rs | 6 | ||||
-rw-r--r-- | crates/completion/src/completions/postfix.rs | 62 | ||||
-rw-r--r-- | crates/completion/src/completions/qualified_path.rs | 56 | ||||
-rw-r--r-- | crates/completion/src/completions/record.rs | 4 | ||||
-rw-r--r-- | crates/completion/src/completions/snippet.rs | 4 | ||||
-rw-r--r-- | crates/completion/src/completions/trait_impl.rs | 4 | ||||
-rw-r--r-- | crates/completion/src/completions/unqualified_path.rs | 179 | ||||
-rw-r--r-- | crates/completion/src/render.rs | 9 | ||||
-rw-r--r-- | crates/completion/src/render/enum_variant.rs | 26 | ||||
-rw-r--r-- | crates/completion/src/render/macro_.rs | 1 | ||||
-rw-r--r-- | crates/completion/src/test_utils.rs | 3 |
16 files changed, 291 insertions, 243 deletions
diff --git a/crates/completion/src/completions.rs b/crates/completion/src/completions.rs index 9b7d6c580..1ef6b5f48 100644 --- a/crates/completion/src/completions.rs +++ b/crates/completion/src/completions.rs | |||
@@ -19,7 +19,7 @@ use hir::{ModPath, ScopeDef, Type}; | |||
19 | use crate::{ | 19 | use crate::{ |
20 | item::Builder, | 20 | item::Builder, |
21 | render::{ | 21 | render::{ |
22 | const_::render_const, enum_variant::render_enum_variant, function::render_fn, | 22 | const_::render_const, enum_variant::render_variant, function::render_fn, |
23 | macro_::render_macro, render_field, render_resolution, render_tuple_field, | 23 | macro_::render_macro, render_field, render_resolution, render_tuple_field, |
24 | type_alias::render_type_alias, RenderContext, | 24 | type_alias::render_type_alias, RenderContext, |
25 | }, | 25 | }, |
@@ -120,20 +120,20 @@ impl Completions { | |||
120 | pub(crate) fn add_qualified_enum_variant( | 120 | pub(crate) fn add_qualified_enum_variant( |
121 | &mut self, | 121 | &mut self, |
122 | ctx: &CompletionContext, | 122 | ctx: &CompletionContext, |
123 | variant: hir::EnumVariant, | 123 | variant: hir::Variant, |
124 | path: ModPath, | 124 | path: ModPath, |
125 | ) { | 125 | ) { |
126 | let item = render_enum_variant(RenderContext::new(ctx), None, None, variant, Some(path)); | 126 | let item = render_variant(RenderContext::new(ctx), None, None, variant, Some(path)); |
127 | self.add(item); | 127 | self.add(item); |
128 | } | 128 | } |
129 | 129 | ||
130 | pub(crate) fn add_enum_variant( | 130 | pub(crate) fn add_enum_variant( |
131 | &mut self, | 131 | &mut self, |
132 | ctx: &CompletionContext, | 132 | ctx: &CompletionContext, |
133 | variant: hir::EnumVariant, | 133 | variant: hir::Variant, |
134 | local_name: Option<String>, | 134 | local_name: Option<String>, |
135 | ) { | 135 | ) { |
136 | let item = render_enum_variant(RenderContext::new(ctx), None, local_name, variant, None); | 136 | let item = render_variant(RenderContext::new(ctx), None, local_name, variant, None); |
137 | self.add(item); | 137 | self.add(item); |
138 | } | 138 | } |
139 | } | 139 | } |
diff --git a/crates/completion/src/completions/attribute.rs b/crates/completion/src/completions/attribute.rs index acce2e7e7..19ce2482f 100644 --- a/crates/completion/src/completions/attribute.rs +++ b/crates/completion/src/completions/attribute.rs | |||
@@ -428,8 +428,8 @@ struct Test {} | |||
428 | at Hash | 428 | at Hash |
429 | at PartialEq | 429 | at PartialEq |
430 | at PartialEq, Eq | 430 | at PartialEq, Eq |
431 | at PartialEq, Eq, PartialOrd, Ord | ||
432 | at PartialEq, PartialOrd | 431 | at PartialEq, PartialOrd |
432 | at PartialEq, Eq, PartialOrd, Ord | ||
433 | "#]], | 433 | "#]], |
434 | ); | 434 | ); |
435 | } | 435 | } |
@@ -457,10 +457,10 @@ struct Test {} | |||
457 | at Clone, Copy | 457 | at Clone, Copy |
458 | at Debug | 458 | at Debug |
459 | at Default | 459 | at Default |
460 | at Eq | ||
461 | at Eq, PartialOrd, Ord | ||
462 | at Hash | 460 | at Hash |
461 | at Eq | ||
463 | at PartialOrd | 462 | at PartialOrd |
463 | at Eq, PartialOrd, Ord | ||
464 | "#]], | 464 | "#]], |
465 | ) | 465 | ) |
466 | } | 466 | } |
@@ -472,14 +472,14 @@ struct Test {} | |||
472 | expect![[r#" | 472 | expect![[r#" |
473 | at allow(…) | 473 | at allow(…) |
474 | at automatically_derived | 474 | at automatically_derived |
475 | at cfg(…) | ||
476 | at cfg_attr(…) | 475 | at cfg_attr(…) |
476 | at cfg(…) | ||
477 | at cold | 477 | at cold |
478 | at deny(…) | 478 | at deny(…) |
479 | at deprecated = "…" | 479 | at deprecated = "…" |
480 | at derive(…) | 480 | at derive(…) |
481 | at doc = "…" | ||
482 | at export_name = "…" | 481 | at export_name = "…" |
482 | at doc = "…" | ||
483 | at forbid(…) | 483 | at forbid(…) |
484 | at ignore = "…" | 484 | at ignore = "…" |
485 | at inline(…) | 485 | at inline(…) |
@@ -518,15 +518,15 @@ struct Test {} | |||
518 | expect![[r#" | 518 | expect![[r#" |
519 | at allow(…) | 519 | at allow(…) |
520 | at automatically_derived | 520 | at automatically_derived |
521 | at cfg(…) | ||
522 | at cfg_attr(…) | 521 | at cfg_attr(…) |
522 | at cfg(…) | ||
523 | at cold | 523 | at cold |
524 | at crate_name = "" | 524 | at crate_name = "" |
525 | at deny(…) | 525 | at deny(…) |
526 | at deprecated = "…" | 526 | at deprecated = "…" |
527 | at derive(…) | 527 | at derive(…) |
528 | at doc = "…" | ||
529 | at export_name = "…" | 528 | at export_name = "…" |
529 | at doc = "…" | ||
530 | at feature(…) | 530 | at feature(…) |
531 | at forbid(…) | 531 | at forbid(…) |
532 | at global_allocator | 532 | at global_allocator |
@@ -538,8 +538,8 @@ struct Test {} | |||
538 | at macro_export | 538 | at macro_export |
539 | at macro_use | 539 | at macro_use |
540 | at must_use = "…" | 540 | at must_use = "…" |
541 | at no_implicit_prelude | ||
542 | at no_link | 541 | at no_link |
542 | at no_implicit_prelude | ||
543 | at no_main | 543 | at no_main |
544 | at no_mangle | 544 | at no_mangle |
545 | at no_std | 545 | at no_std |
diff --git a/crates/completion/src/completions/dot.rs b/crates/completion/src/completions/dot.rs index c9875045a..551ef1771 100644 --- a/crates/completion/src/completions/dot.rs +++ b/crates/completion/src/completions/dot.rs | |||
@@ -82,8 +82,8 @@ impl S { | |||
82 | fn foo(s: S) { s.<|> } | 82 | fn foo(s: S) { s.<|> } |
83 | "#, | 83 | "#, |
84 | expect![[r#" | 84 | expect![[r#" |
85 | me bar() fn bar(&self) | ||
86 | fd foo u32 | 85 | fd foo u32 |
86 | me bar() fn bar(&self) | ||
87 | "#]], | 87 | "#]], |
88 | ); | 88 | ); |
89 | } | 89 | } |
@@ -98,8 +98,8 @@ impl S { | |||
98 | } | 98 | } |
99 | "#, | 99 | "#, |
100 | expect![[r#" | 100 | expect![[r#" |
101 | me foo() fn foo(self) | ||
102 | fd the_field (u32,) | 101 | fd the_field (u32,) |
102 | me foo() fn foo(self) | ||
103 | "#]], | 103 | "#]], |
104 | ) | 104 | ) |
105 | } | 105 | } |
@@ -114,8 +114,8 @@ impl A { | |||
114 | } | 114 | } |
115 | "#, | 115 | "#, |
116 | expect![[r#" | 116 | expect![[r#" |
117 | me foo() fn foo(&self) | ||
118 | fd the_field (u32, i32) | 117 | fd the_field (u32, i32) |
118 | me foo() fn foo(&self) | ||
119 | "#]], | 119 | "#]], |
120 | ) | 120 | ) |
121 | } | 121 | } |
@@ -147,8 +147,8 @@ mod inner { | |||
147 | fn foo(a: inner::A) { a.<|> } | 147 | fn foo(a: inner::A) { a.<|> } |
148 | "#, | 148 | "#, |
149 | expect![[r#" | 149 | expect![[r#" |
150 | fd crate_field u32 | ||
151 | fd pub_field u32 | 150 | fd pub_field u32 |
151 | fd crate_field u32 | ||
152 | fd super_field u32 | 152 | fd super_field u32 |
153 | "#]], | 153 | "#]], |
154 | ); | 154 | ); |
diff --git a/crates/completion/src/completions/keyword.rs b/crates/completion/src/completions/keyword.rs index 720349b9d..1859dec70 100644 --- a/crates/completion/src/completions/keyword.rs +++ b/crates/completion/src/completions/keyword.rs | |||
@@ -223,21 +223,21 @@ mod tests { | |||
223 | check( | 223 | check( |
224 | r"m<|>", | 224 | r"m<|>", |
225 | expect![[r#" | 225 | expect![[r#" |
226 | kw const | ||
227 | kw enum | ||
228 | kw extern | ||
229 | kw fn | 226 | kw fn |
227 | kw use | ||
230 | kw impl | 228 | kw impl |
231 | kw mod | ||
232 | kw pub | ||
233 | kw pub(crate) | ||
234 | kw static | ||
235 | kw struct | ||
236 | kw trait | 229 | kw trait |
237 | kw type | 230 | kw enum |
231 | kw struct | ||
238 | kw union | 232 | kw union |
233 | kw mod | ||
234 | kw const | ||
235 | kw type | ||
236 | kw static | ||
237 | kw extern | ||
239 | kw unsafe | 238 | kw unsafe |
240 | kw use | 239 | kw pub(crate) |
240 | kw pub | ||
241 | "#]], | 241 | "#]], |
242 | ); | 242 | ); |
243 | } | 243 | } |
@@ -247,23 +247,23 @@ mod tests { | |||
247 | check( | 247 | check( |
248 | r"fn quux() { <|> }", | 248 | r"fn quux() { <|> }", |
249 | expect![[r#" | 249 | expect![[r#" |
250 | kw const | ||
251 | kw extern | ||
252 | kw fn | 250 | kw fn |
251 | kw use | ||
252 | kw impl | ||
253 | kw trait | ||
254 | kw match | ||
255 | kw while | ||
256 | kw loop | ||
253 | kw if | 257 | kw if |
254 | kw if let | 258 | kw if let |
255 | kw impl | ||
256 | kw let | 259 | kw let |
257 | kw loop | ||
258 | kw match | ||
259 | kw mod | 260 | kw mod |
260 | kw return | 261 | kw const |
261 | kw static | ||
262 | kw trait | ||
263 | kw type | 262 | kw type |
263 | kw static | ||
264 | kw extern | ||
264 | kw unsafe | 265 | kw unsafe |
265 | kw use | 266 | kw return |
266 | kw while | ||
267 | "#]], | 267 | "#]], |
268 | ); | 268 | ); |
269 | } | 269 | } |
@@ -273,23 +273,23 @@ mod tests { | |||
273 | check( | 273 | check( |
274 | r"fn quux() { if true { <|> } }", | 274 | r"fn quux() { if true { <|> } }", |
275 | expect![[r#" | 275 | expect![[r#" |
276 | kw const | ||
277 | kw extern | ||
278 | kw fn | 276 | kw fn |
277 | kw use | ||
278 | kw impl | ||
279 | kw trait | ||
280 | kw match | ||
281 | kw while | ||
282 | kw loop | ||
279 | kw if | 283 | kw if |
280 | kw if let | 284 | kw if let |
281 | kw impl | ||
282 | kw let | 285 | kw let |
283 | kw loop | ||
284 | kw match | ||
285 | kw mod | 286 | kw mod |
286 | kw return | 287 | kw const |
287 | kw static | ||
288 | kw trait | ||
289 | kw type | 288 | kw type |
289 | kw static | ||
290 | kw extern | ||
290 | kw unsafe | 291 | kw unsafe |
291 | kw use | 292 | kw return |
292 | kw while | ||
293 | "#]], | 293 | "#]], |
294 | ); | 294 | ); |
295 | } | 295 | } |
@@ -299,25 +299,25 @@ mod tests { | |||
299 | check( | 299 | check( |
300 | r#"fn quux() { if true { () } <|> }"#, | 300 | r#"fn quux() { if true { () } <|> }"#, |
301 | expect![[r#" | 301 | expect![[r#" |
302 | kw const | ||
303 | kw else | ||
304 | kw else if | ||
305 | kw extern | ||
306 | kw fn | 302 | kw fn |
303 | kw use | ||
304 | kw impl | ||
305 | kw trait | ||
306 | kw match | ||
307 | kw while | ||
308 | kw loop | ||
307 | kw if | 309 | kw if |
308 | kw if let | 310 | kw if let |
309 | kw impl | ||
310 | kw let | 311 | kw let |
311 | kw loop | 312 | kw else |
312 | kw match | 313 | kw else if |
313 | kw mod | 314 | kw mod |
314 | kw return | 315 | kw const |
315 | kw static | ||
316 | kw trait | ||
317 | kw type | 316 | kw type |
317 | kw static | ||
318 | kw extern | ||
318 | kw unsafe | 319 | kw unsafe |
319 | kw use | 320 | kw return |
320 | kw while | ||
321 | "#]], | 321 | "#]], |
322 | ); | 322 | ); |
323 | check_edit( | 323 | check_edit( |
@@ -336,13 +336,13 @@ fn quux() -> i32 { | |||
336 | } | 336 | } |
337 | "#, | 337 | "#, |
338 | expect![[r#" | 338 | expect![[r#" |
339 | kw match | ||
340 | kw while | ||
341 | kw loop | ||
339 | kw if | 342 | kw if |
340 | kw if let | 343 | kw if let |
341 | kw loop | ||
342 | kw match | ||
343 | kw return | ||
344 | kw unsafe | 344 | kw unsafe |
345 | kw while | 345 | kw return |
346 | "#]], | 346 | "#]], |
347 | ); | 347 | ); |
348 | } | 348 | } |
@@ -352,8 +352,8 @@ fn quux() -> i32 { | |||
352 | check( | 352 | check( |
353 | r"trait My { <|> }", | 353 | r"trait My { <|> }", |
354 | expect![[r#" | 354 | expect![[r#" |
355 | kw const | ||
356 | kw fn | 355 | kw fn |
356 | kw const | ||
357 | kw type | 357 | kw type |
358 | kw unsafe | 358 | kw unsafe |
359 | "#]], | 359 | "#]], |
@@ -365,12 +365,12 @@ fn quux() -> i32 { | |||
365 | check( | 365 | check( |
366 | r"impl My { <|> }", | 366 | r"impl My { <|> }", |
367 | expect![[r#" | 367 | expect![[r#" |
368 | kw const | ||
369 | kw fn | 368 | kw fn |
370 | kw pub | 369 | kw const |
371 | kw pub(crate) | ||
372 | kw type | 370 | kw type |
373 | kw unsafe | 371 | kw unsafe |
372 | kw pub(crate) | ||
373 | kw pub | ||
374 | "#]], | 374 | "#]], |
375 | ); | 375 | ); |
376 | } | 376 | } |
@@ -380,25 +380,25 @@ fn quux() -> i32 { | |||
380 | check( | 380 | check( |
381 | r"fn my() { loop { <|> } }", | 381 | r"fn my() { loop { <|> } }", |
382 | expect![[r#" | 382 | expect![[r#" |
383 | kw break | ||
384 | kw const | ||
385 | kw continue | ||
386 | kw extern | ||
387 | kw fn | 383 | kw fn |
384 | kw use | ||
385 | kw impl | ||
386 | kw trait | ||
387 | kw match | ||
388 | kw while | ||
389 | kw loop | ||
388 | kw if | 390 | kw if |
389 | kw if let | 391 | kw if let |
390 | kw impl | ||
391 | kw let | 392 | kw let |
392 | kw loop | ||
393 | kw match | ||
394 | kw mod | 393 | kw mod |
395 | kw return | 394 | kw const |
396 | kw static | ||
397 | kw trait | ||
398 | kw type | 395 | kw type |
396 | kw static | ||
397 | kw extern | ||
399 | kw unsafe | 398 | kw unsafe |
400 | kw use | 399 | kw continue |
401 | kw while | 400 | kw break |
401 | kw return | ||
402 | "#]], | 402 | "#]], |
403 | ); | 403 | ); |
404 | } | 404 | } |
@@ -409,8 +409,8 @@ fn quux() -> i32 { | |||
409 | r"unsafe <|>", | 409 | r"unsafe <|>", |
410 | expect![[r#" | 410 | expect![[r#" |
411 | kw fn | 411 | kw fn |
412 | kw impl | ||
413 | kw trait | 412 | kw trait |
413 | kw impl | ||
414 | "#]], | 414 | "#]], |
415 | ); | 415 | ); |
416 | } | 416 | } |
@@ -421,8 +421,8 @@ fn quux() -> i32 { | |||
421 | r"fn my_fn() { unsafe <|> }", | 421 | r"fn my_fn() { unsafe <|> }", |
422 | expect![[r#" | 422 | expect![[r#" |
423 | kw fn | 423 | kw fn |
424 | kw impl | ||
425 | kw trait | 424 | kw trait |
425 | kw impl | ||
426 | "#]], | 426 | "#]], |
427 | ); | 427 | ); |
428 | } | 428 | } |
@@ -542,12 +542,12 @@ pub mod future { | |||
542 | check( | 542 | check( |
543 | r#"fn main() { let _ = <|> }"#, | 543 | r#"fn main() { let _ = <|> }"#, |
544 | expect![[r#" | 544 | expect![[r#" |
545 | kw match | ||
546 | kw while | ||
547 | kw loop | ||
545 | kw if | 548 | kw if |
546 | kw if let | 549 | kw if let |
547 | kw loop | ||
548 | kw match | ||
549 | kw return | 550 | kw return |
550 | kw while | ||
551 | "#]], | 551 | "#]], |
552 | ) | 552 | ) |
553 | } | 553 | } |
@@ -562,8 +562,8 @@ struct Foo { | |||
562 | } | 562 | } |
563 | "#, | 563 | "#, |
564 | expect![[r#" | 564 | expect![[r#" |
565 | kw pub | ||
566 | kw pub(crate) | 565 | kw pub(crate) |
566 | kw pub | ||
567 | "#]], | 567 | "#]], |
568 | ) | 568 | ) |
569 | } | 569 | } |
@@ -600,12 +600,12 @@ fn foo() { | |||
600 | } | 600 | } |
601 | "#, | 601 | "#, |
602 | expect![[r#" | 602 | expect![[r#" |
603 | kw match | ||
604 | kw while | ||
605 | kw loop | ||
603 | kw if | 606 | kw if |
604 | kw if let | 607 | kw if let |
605 | kw loop | ||
606 | kw match | ||
607 | kw return | 608 | kw return |
608 | kw while | ||
609 | "#]], | 609 | "#]], |
610 | ); | 610 | ); |
611 | } | 611 | } |
diff --git a/crates/completion/src/completions/mod_.rs b/crates/completion/src/completions/mod_.rs index c96f84171..f77864b77 100644 --- a/crates/completion/src/completions/mod_.rs +++ b/crates/completion/src/completions/mod_.rs | |||
@@ -170,8 +170,8 @@ mod tests { | |||
170 | fn ignored_bar() {} | 170 | fn ignored_bar() {} |
171 | "#, | 171 | "#, |
172 | expect![[r#" | 172 | expect![[r#" |
173 | md bar; | ||
174 | md foo; | 173 | md foo; |
174 | md bar; | ||
175 | "#]], | 175 | "#]], |
176 | ); | 176 | ); |
177 | } | 177 | } |
@@ -207,8 +207,8 @@ mod tests { | |||
207 | fn ignored_bar() {} | 207 | fn ignored_bar() {} |
208 | "#, | 208 | "#, |
209 | expect![[r#" | 209 | expect![[r#" |
210 | md bar; | ||
211 | md foo; | 210 | md foo; |
211 | md bar; | ||
212 | "#]], | 212 | "#]], |
213 | ); | 213 | ); |
214 | } | 214 | } |
diff --git a/crates/completion/src/completions/pattern.rs b/crates/completion/src/completions/pattern.rs index 4f63ff0ef..4d56731ec 100644 --- a/crates/completion/src/completions/pattern.rs +++ b/crates/completion/src/completions/pattern.rs | |||
@@ -23,7 +23,7 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { | |||
23 | def, | 23 | def, |
24 | hir::ModuleDef::Adt(hir::Adt::Enum(..)) | 24 | hir::ModuleDef::Adt(hir::Adt::Enum(..)) |
25 | | hir::ModuleDef::Adt(hir::Adt::Struct(..)) | 25 | | hir::ModuleDef::Adt(hir::Adt::Struct(..)) |
26 | | hir::ModuleDef::EnumVariant(..) | 26 | | hir::ModuleDef::Variant(..) |
27 | | hir::ModuleDef::Const(..) | 27 | | hir::ModuleDef::Const(..) |
28 | | hir::ModuleDef::Module(..) | 28 | | hir::ModuleDef::Module(..) |
29 | ) | 29 | ) |
@@ -66,10 +66,10 @@ fn foo() { | |||
66 | } | 66 | } |
67 | "#, | 67 | "#, |
68 | expect![[r#" | 68 | expect![[r#" |
69 | st Bar | ||
70 | en E | 69 | en E |
71 | ev X () | ||
72 | ct Z | 70 | ct Z |
71 | st Bar | ||
72 | ev X () | ||
73 | md m | 73 | md m |
74 | "#]], | 74 | "#]], |
75 | ); | 75 | ); |
diff --git a/crates/completion/src/completions/postfix.rs b/crates/completion/src/completions/postfix.rs index c8ba63cd3..d6db82a93 100644 --- a/crates/completion/src/completions/postfix.rs +++ b/crates/completion/src/completions/postfix.rs | |||
@@ -315,20 +315,20 @@ fn main() { | |||
315 | } | 315 | } |
316 | "#, | 316 | "#, |
317 | expect![[r#" | 317 | expect![[r#" |
318 | sn box Box::new(expr) | ||
319 | sn call function(expr) | ||
320 | sn dbg dbg!(expr) | ||
321 | sn dbgr dbg!(&expr) | ||
322 | sn if if expr {} | 318 | sn if if expr {} |
323 | sn let let | 319 | sn while while expr {} |
324 | sn letm let mut | ||
325 | sn match match expr {} | ||
326 | sn not !expr | 320 | sn not !expr |
327 | sn ok Ok(expr) | ||
328 | sn ref &expr | 321 | sn ref &expr |
329 | sn refm &mut expr | 322 | sn refm &mut expr |
323 | sn match match expr {} | ||
324 | sn box Box::new(expr) | ||
325 | sn ok Ok(expr) | ||
330 | sn some Some(expr) | 326 | sn some Some(expr) |
331 | sn while while expr {} | 327 | sn dbg dbg!(expr) |
328 | sn dbgr dbg!(&expr) | ||
329 | sn call function(expr) | ||
330 | sn let let | ||
331 | sn letm let mut | ||
332 | "#]], | 332 | "#]], |
333 | ); | 333 | ); |
334 | } | 334 | } |
@@ -347,18 +347,18 @@ fn main() { | |||
347 | } | 347 | } |
348 | "#, | 348 | "#, |
349 | expect![[r#" | 349 | expect![[r#" |
350 | sn box Box::new(expr) | ||
351 | sn call function(expr) | ||
352 | sn dbg dbg!(expr) | ||
353 | sn dbgr dbg!(&expr) | ||
354 | sn if if expr {} | 350 | sn if if expr {} |
355 | sn match match expr {} | 351 | sn while while expr {} |
356 | sn not !expr | 352 | sn not !expr |
357 | sn ok Ok(expr) | ||
358 | sn ref &expr | 353 | sn ref &expr |
359 | sn refm &mut expr | 354 | sn refm &mut expr |
355 | sn match match expr {} | ||
356 | sn box Box::new(expr) | ||
357 | sn ok Ok(expr) | ||
360 | sn some Some(expr) | 358 | sn some Some(expr) |
361 | sn while while expr {} | 359 | sn dbg dbg!(expr) |
360 | sn dbgr dbg!(&expr) | ||
361 | sn call function(expr) | ||
362 | "#]], | 362 | "#]], |
363 | ); | 363 | ); |
364 | } | 364 | } |
@@ -373,17 +373,17 @@ fn main() { | |||
373 | } | 373 | } |
374 | "#, | 374 | "#, |
375 | expect![[r#" | 375 | expect![[r#" |
376 | sn ref &expr | ||
377 | sn refm &mut expr | ||
378 | sn match match expr {} | ||
376 | sn box Box::new(expr) | 379 | sn box Box::new(expr) |
377 | sn call function(expr) | 380 | sn ok Ok(expr) |
381 | sn some Some(expr) | ||
378 | sn dbg dbg!(expr) | 382 | sn dbg dbg!(expr) |
379 | sn dbgr dbg!(&expr) | 383 | sn dbgr dbg!(&expr) |
384 | sn call function(expr) | ||
380 | sn let let | 385 | sn let let |
381 | sn letm let mut | 386 | sn letm let mut |
382 | sn match match expr {} | ||
383 | sn ok Ok(expr) | ||
384 | sn ref &expr | ||
385 | sn refm &mut expr | ||
386 | sn some Some(expr) | ||
387 | "#]], | 387 | "#]], |
388 | ) | 388 | ) |
389 | } | 389 | } |
@@ -398,20 +398,20 @@ fn main() { | |||
398 | } | 398 | } |
399 | "#, | 399 | "#, |
400 | expect![[r#" | 400 | expect![[r#" |
401 | sn box Box::new(expr) | ||
402 | sn call function(expr) | ||
403 | sn dbg dbg!(expr) | ||
404 | sn dbgr dbg!(&expr) | ||
405 | sn if if expr {} | 401 | sn if if expr {} |
406 | sn let let | 402 | sn while while expr {} |
407 | sn letm let mut | ||
408 | sn match match expr {} | ||
409 | sn not !expr | 403 | sn not !expr |
410 | sn ok Ok(expr) | ||
411 | sn ref &expr | 404 | sn ref &expr |
412 | sn refm &mut expr | 405 | sn refm &mut expr |
406 | sn match match expr {} | ||
407 | sn box Box::new(expr) | ||
408 | sn ok Ok(expr) | ||
413 | sn some Some(expr) | 409 | sn some Some(expr) |
414 | sn while while expr {} | 410 | sn dbg dbg!(expr) |
411 | sn dbgr dbg!(&expr) | ||
412 | sn call function(expr) | ||
413 | sn let let | ||
414 | sn letm let mut | ||
415 | "#]], | 415 | "#]], |
416 | ); | 416 | ); |
417 | } | 417 | } |
diff --git a/crates/completion/src/completions/qualified_path.rs b/crates/completion/src/completions/qualified_path.rs index bc23bea3f..1300f00b2 100644 --- a/crates/completion/src/completions/qualified_path.rs +++ b/crates/completion/src/completions/qualified_path.rs | |||
@@ -199,22 +199,22 @@ use self::{foo::*, bar<|>}; | |||
199 | check_builtin( | 199 | check_builtin( |
200 | r#"fn main() { let _: <|> = 92; }"#, | 200 | r#"fn main() { let _: <|> = 92; }"#, |
201 | expect![[r#" | 201 | expect![[r#" |
202 | bt u32 | ||
202 | bt bool | 203 | bt bool |
203 | bt char | 204 | bt u8 |
205 | bt isize | ||
206 | bt u16 | ||
207 | bt u64 | ||
208 | bt u128 | ||
204 | bt f32 | 209 | bt f32 |
205 | bt f64 | ||
206 | bt i128 | 210 | bt i128 |
207 | bt i16 | 211 | bt i16 |
208 | bt i32 | 212 | bt str |
209 | bt i64 | 213 | bt i64 |
214 | bt char | ||
215 | bt f64 | ||
216 | bt i32 | ||
210 | bt i8 | 217 | bt i8 |
211 | bt isize | ||
212 | bt str | ||
213 | bt u128 | ||
214 | bt u16 | ||
215 | bt u32 | ||
216 | bt u64 | ||
217 | bt u8 | ||
218 | bt usize | 218 | bt usize |
219 | "#]], | 219 | "#]], |
220 | ); | 220 | ); |
@@ -279,8 +279,8 @@ struct Spam; | |||
279 | use crate::Sp<|> | 279 | use crate::Sp<|> |
280 | "#, | 280 | "#, |
281 | expect![[r#" | 281 | expect![[r#" |
282 | st Spam | ||
283 | md foo | 282 | md foo |
283 | st Spam | ||
284 | "#]], | 284 | "#]], |
285 | ); | 285 | ); |
286 | } | 286 | } |
@@ -296,8 +296,8 @@ struct Spam; | |||
296 | use crate::{Sp<|>}; | 296 | use crate::{Sp<|>}; |
297 | "#, | 297 | "#, |
298 | expect![[r#" | 298 | expect![[r#" |
299 | st Spam | ||
300 | md foo | 299 | md foo |
300 | st Spam | ||
301 | "#]], | 301 | "#]], |
302 | ); | 302 | ); |
303 | } | 303 | } |
@@ -330,8 +330,8 @@ enum E { Foo, Bar(i32) } | |||
330 | fn foo() { let _ = E::<|> } | 330 | fn foo() { let _ = E::<|> } |
331 | "#, | 331 | "#, |
332 | expect![[r#" | 332 | expect![[r#" |
333 | ev Bar(…) (i32) | ||
334 | ev Foo () | 333 | ev Foo () |
334 | ev Bar(…) (i32) | ||
335 | "#]], | 335 | "#]], |
336 | ); | 336 | ); |
337 | } | 337 | } |
@@ -353,10 +353,10 @@ impl S { | |||
353 | fn foo() { let _ = S::<|> } | 353 | fn foo() { let _ = S::<|> } |
354 | "#, | 354 | "#, |
355 | expect![[r#" | 355 | expect![[r#" |
356 | ct C const C: i32 = 42; | ||
357 | ta T type T = i32; | ||
358 | fn a() fn a() | 356 | fn a() fn a() |
359 | me b(…) fn b(&self) | 357 | me b(…) fn b(&self) |
358 | ct C const C: i32 = 42; | ||
359 | ta T type T = i32; | ||
360 | "#]], | 360 | "#]], |
361 | ); | 361 | ); |
362 | } | 362 | } |
@@ -381,9 +381,9 @@ mod m { | |||
381 | fn foo() { let _ = S::<|> } | 381 | fn foo() { let _ = S::<|> } |
382 | "#, | 382 | "#, |
383 | expect![[r#" | 383 | expect![[r#" |
384 | fn public_method() pub(crate) fn public_method() | ||
384 | ct PUBLIC_CONST pub(crate) const PUBLIC_CONST: u32 = 1; | 385 | ct PUBLIC_CONST pub(crate) const PUBLIC_CONST: u32 = 1; |
385 | ta PublicType pub(crate) type PublicType = u32; | 386 | ta PublicType pub(crate) type PublicType = u32; |
386 | fn public_method() pub(crate) fn public_method() | ||
387 | "#]], | 387 | "#]], |
388 | ); | 388 | ); |
389 | } | 389 | } |
@@ -503,14 +503,14 @@ trait Sub: Super { | |||
503 | fn foo<T: Sub>() { T::<|> } | 503 | fn foo<T: Sub>() { T::<|> } |
504 | "#, | 504 | "#, |
505 | expect![[r#" | 505 | expect![[r#" |
506 | ct C2 const C2: (); | ||
507 | ct CONST const CONST: u8; | ||
508 | ta SubTy type SubTy; | 506 | ta SubTy type SubTy; |
509 | ta Ty type Ty; | 507 | ta Ty type Ty; |
510 | fn func() fn func() | 508 | ct C2 const C2: (); |
511 | me method(…) fn method(&self) | ||
512 | fn subfunc() fn subfunc() | 509 | fn subfunc() fn subfunc() |
513 | me submethod(…) fn submethod(&self) | 510 | me submethod(…) fn submethod(&self) |
511 | ct CONST const CONST: u8; | ||
512 | fn func() fn func() | ||
513 | me method(…) fn method(&self) | ||
514 | "#]], | 514 | "#]], |
515 | ); | 515 | ); |
516 | } | 516 | } |
@@ -543,12 +543,12 @@ impl<T> Sub for Wrap<T> { | |||
543 | } | 543 | } |
544 | "#, | 544 | "#, |
545 | expect![[r#" | 545 | expect![[r#" |
546 | ct C2 const C2: () = (); | ||
547 | ct CONST const CONST: u8 = 0; | ||
548 | ta SubTy type SubTy; | 546 | ta SubTy type SubTy; |
549 | ta Ty type Ty; | 547 | ta Ty type Ty; |
548 | ct CONST const CONST: u8 = 0; | ||
550 | fn func() fn func() | 549 | fn func() fn func() |
551 | me method(…) fn method(&self) | 550 | me method(…) fn method(&self) |
551 | ct C2 const C2: () = (); | ||
552 | fn subfunc() fn subfunc() | 552 | fn subfunc() fn subfunc() |
553 | me submethod(…) fn submethod(&self) | 553 | me submethod(…) fn submethod(&self) |
554 | "#]], | 554 | "#]], |
@@ -567,8 +567,8 @@ impl T { fn bar() {} } | |||
567 | fn main() { T::<|>; } | 567 | fn main() { T::<|>; } |
568 | "#, | 568 | "#, |
569 | expect![[r#" | 569 | expect![[r#" |
570 | fn bar() fn bar() | ||
571 | fn foo() fn foo() | 570 | fn foo() fn foo() |
571 | fn bar() fn bar() | ||
572 | "#]], | 572 | "#]], |
573 | ); | 573 | ); |
574 | } | 574 | } |
@@ -583,9 +583,9 @@ macro_rules! foo { () => {} } | |||
583 | fn main() { let _ = crate::<|> } | 583 | fn main() { let _ = crate::<|> } |
584 | "#, | 584 | "#, |
585 | expect![[r##" | 585 | expect![[r##" |
586 | fn main() fn main() | ||
586 | ma foo!(…) #[macro_export] | 587 | ma foo!(…) #[macro_export] |
587 | macro_rules! foo | 588 | macro_rules! foo |
588 | fn main() fn main() | ||
589 | "##]], | 589 | "##]], |
590 | ); | 590 | ); |
591 | } | 591 | } |
@@ -603,8 +603,8 @@ mod a { | |||
603 | } | 603 | } |
604 | "#, | 604 | "#, |
605 | expect![[r#" | 605 | expect![[r#" |
606 | ct A | ||
607 | md b | 606 | md b |
607 | ct A | ||
608 | "#]], | 608 | "#]], |
609 | ); | 609 | ); |
610 | } | 610 | } |
@@ -628,8 +628,8 @@ mod p { | |||
628 | "#, | 628 | "#, |
629 | expect![[r#" | 629 | expect![[r#" |
630 | ct RIGHT_CONST | 630 | ct RIGHT_CONST |
631 | st RightType | ||
632 | fn right_fn() fn wrong_fn() | 631 | fn right_fn() fn wrong_fn() |
632 | st RightType | ||
633 | "#]], | 633 | "#]], |
634 | ); | 634 | ); |
635 | 635 | ||
@@ -675,8 +675,8 @@ fn main() { m!(self::f<|>); } | |||
675 | fn foo() {} | 675 | fn foo() {} |
676 | "#, | 676 | "#, |
677 | expect![[r#" | 677 | expect![[r#" |
678 | fn foo() fn foo() | ||
679 | fn main() fn main() | 678 | fn main() fn main() |
679 | fn foo() fn foo() | ||
680 | "#]], | 680 | "#]], |
681 | ); | 681 | ); |
682 | } | 682 | } |
@@ -747,8 +747,8 @@ fn main() { | |||
747 | } | 747 | } |
748 | "#, | 748 | "#, |
749 | expect![[r#" | 749 | expect![[r#" |
750 | fn foo(…) fn foo(a: i32, b: i32) | ||
751 | fn main() fn main() | 750 | fn main() fn main() |
751 | fn foo(…) fn foo(a: i32, b: i32) | ||
752 | "#]], | 752 | "#]], |
753 | ); | 753 | ); |
754 | } | 754 | } |
diff --git a/crates/completion/src/completions/record.rs b/crates/completion/src/completions/record.rs index eaa44c97d..91bf4a8ad 100644 --- a/crates/completion/src/completions/record.rs +++ b/crates/completion/src/completions/record.rs | |||
@@ -94,9 +94,9 @@ fn process(f: S) { | |||
94 | check_snippet( | 94 | check_snippet( |
95 | test_code, | 95 | test_code, |
96 | expect![[r#" | 96 | expect![[r#" |
97 | fd ..Default::default() | ||
98 | sn pd | 97 | sn pd |
99 | sn ppd | 98 | sn ppd |
99 | fd ..Default::default() | ||
100 | "#]], | 100 | "#]], |
101 | ); | 101 | ); |
102 | } | 102 | } |
@@ -160,8 +160,8 @@ fn process(e: E) { | |||
160 | } | 160 | } |
161 | "#, | 161 | "#, |
162 | expect![[r#" | 162 | expect![[r#" |
163 | fd bar () | ||
164 | fd foo u32 | 163 | fd foo u32 |
164 | fd bar () | ||
165 | "#]], | 165 | "#]], |
166 | ); | 166 | ); |
167 | } | 167 | } |
diff --git a/crates/completion/src/completions/snippet.rs b/crates/completion/src/completions/snippet.rs index 6f0c00078..842590130 100644 --- a/crates/completion/src/completions/snippet.rs +++ b/crates/completion/src/completions/snippet.rs | |||
@@ -105,9 +105,9 @@ mod tests { | |||
105 | } | 105 | } |
106 | "#, | 106 | "#, |
107 | expect![[r#" | 107 | expect![[r#" |
108 | sn macro_rules | ||
109 | sn tfn (Test function) | ||
110 | sn tmod (Test module) | 108 | sn tmod (Test module) |
109 | sn tfn (Test function) | ||
110 | sn macro_rules | ||
111 | "#]], | 111 | "#]], |
112 | ) | 112 | ) |
113 | } | 113 | } |
diff --git a/crates/completion/src/completions/trait_impl.rs b/crates/completion/src/completions/trait_impl.rs index e2fe44aff..c4e0d0669 100644 --- a/crates/completion/src/completions/trait_impl.rs +++ b/crates/completion/src/completions/trait_impl.rs | |||
@@ -266,10 +266,10 @@ impl Test for T { | |||
266 | } | 266 | } |
267 | "#, | 267 | "#, |
268 | expect![[" | 268 | expect![[" |
269 | ta type TestType = \n\ | ||
269 | ct const TEST_CONST: u16 = \n\ | 270 | ct const TEST_CONST: u16 = \n\ |
270 | fn fn test() | 271 | fn fn test() |
271 | ta type TestType = \n\ | 272 | "]], |
272 | "]], | ||
273 | ); | 273 | ); |
274 | } | 274 | } |
275 | 275 | ||
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index b9315f6c0..099ffb4d4 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Completion of names from the current scope, e.g. locals and imported items. | 1 | //! Completion of names from the current scope, e.g. locals and imported items. |
2 | 2 | ||
3 | use either::Either; | 3 | use either::Either; |
4 | use hir::{Adt, ModuleDef, ScopeDef, Type}; | 4 | use hir::{Adt, ModPath, ModuleDef, ScopeDef, Type}; |
5 | use ide_db::helpers::insert_use::ImportScope; | 5 | use ide_db::helpers::insert_use::ImportScope; |
6 | use ide_db::imports_locator; | 6 | use ide_db::imports_locator; |
7 | use syntax::AstNode; | 7 | use syntax::AstNode; |
@@ -126,7 +126,7 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<() | |||
126 | let anchor = ctx.name_ref_syntax.as_ref()?; | 126 | let anchor = ctx.name_ref_syntax.as_ref()?; |
127 | let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?; | 127 | let import_scope = ImportScope::find_insert_use_container(anchor.syntax(), &ctx.sema)?; |
128 | 128 | ||
129 | let possible_imports = imports_locator::find_similar_imports( | 129 | let mut all_mod_paths = imports_locator::find_similar_imports( |
130 | &ctx.sema, | 130 | &ctx.sema, |
131 | ctx.krate?, | 131 | ctx.krate?, |
132 | Some(100), | 132 | Some(100), |
@@ -144,33 +144,65 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<() | |||
144 | }) | 144 | }) |
145 | }) | 145 | }) |
146 | .filter(|(mod_path, _)| mod_path.len() > 1) | 146 | .filter(|(mod_path, _)| mod_path.len() > 1) |
147 | .filter_map(|(import_path, definition)| { | 147 | .collect::<Vec<_>>(); |
148 | |||
149 | let user_input_lowercased = potential_import_name.to_lowercase(); | ||
150 | all_mod_paths.sort_by_cached_key(|(mod_path, _)| { | ||
151 | compute_fuzzy_completion_order_key(mod_path, &user_input_lowercased) | ||
152 | }); | ||
153 | |||
154 | acc.add_all(all_mod_paths.into_iter().filter_map(|(import_path, definition)| { | ||
148 | render_resolution_with_import( | 155 | render_resolution_with_import( |
149 | RenderContext::new(ctx), | 156 | RenderContext::new(ctx), |
150 | ImportEdit { import_path, import_scope: import_scope.clone() }, | 157 | ImportEdit { import_path, import_scope: import_scope.clone() }, |
151 | &definition, | 158 | &definition, |
152 | ) | 159 | ) |
153 | }); | 160 | })); |
154 | |||
155 | acc.add_all(possible_imports); | ||
156 | Some(()) | 161 | Some(()) |
157 | } | 162 | } |
158 | 163 | ||
164 | fn compute_fuzzy_completion_order_key( | ||
165 | proposed_mod_path: &ModPath, | ||
166 | user_input_lowercased: &str, | ||
167 | ) -> usize { | ||
168 | mark::hit!(certain_fuzzy_order_test); | ||
169 | let proposed_import_name = match proposed_mod_path.segments.last() { | ||
170 | Some(name) => name.to_string().to_lowercase(), | ||
171 | None => return usize::MAX, | ||
172 | }; | ||
173 | match proposed_import_name.match_indices(user_input_lowercased).next() { | ||
174 | Some((first_matching_index, _)) => first_matching_index, | ||
175 | None => usize::MAX, | ||
176 | } | ||
177 | } | ||
178 | |||
159 | #[cfg(test)] | 179 | #[cfg(test)] |
160 | mod tests { | 180 | mod tests { |
161 | use expect_test::{expect, Expect}; | 181 | use expect_test::{expect, Expect}; |
162 | use test_utils::mark; | 182 | use test_utils::mark; |
163 | 183 | ||
164 | use crate::{ | 184 | use crate::{ |
165 | test_utils::{check_edit, check_edit_with_config, completion_list}, | 185 | test_utils::{check_edit, check_edit_with_config, completion_list_with_config}, |
166 | CompletionConfig, CompletionKind, | 186 | CompletionConfig, CompletionKind, |
167 | }; | 187 | }; |
168 | 188 | ||
169 | fn check(ra_fixture: &str, expect: Expect) { | 189 | fn check(ra_fixture: &str, expect: Expect) { |
170 | let actual = completion_list(ra_fixture, CompletionKind::Reference); | 190 | check_with_config(CompletionConfig::default(), ra_fixture, expect); |
191 | } | ||
192 | |||
193 | fn check_with_config(config: CompletionConfig, ra_fixture: &str, expect: Expect) { | ||
194 | let actual = completion_list_with_config(config, ra_fixture, CompletionKind::Reference); | ||
171 | expect.assert_eq(&actual) | 195 | expect.assert_eq(&actual) |
172 | } | 196 | } |
173 | 197 | ||
198 | fn fuzzy_completion_config() -> CompletionConfig { | ||
199 | let mut completion_config = CompletionConfig::default(); | ||
200 | completion_config | ||
201 | .active_resolve_capabilities | ||
202 | .insert(crate::CompletionResolveCapability::AdditionalTextEdits); | ||
203 | completion_config | ||
204 | } | ||
205 | |||
174 | #[test] | 206 | #[test] |
175 | fn self_fulfilling_completion() { | 207 | fn self_fulfilling_completion() { |
176 | mark::check!(self_fulfilling_completion); | 208 | mark::check!(self_fulfilling_completion); |
@@ -246,9 +278,9 @@ fn quux(x: i32) { | |||
246 | } | 278 | } |
247 | "#, | 279 | "#, |
248 | expect![[r#" | 280 | expect![[r#" |
249 | fn quux(…) fn quux(x: i32) | ||
250 | bn x i32 | ||
251 | bn y i32 | 281 | bn y i32 |
282 | bn x i32 | ||
283 | fn quux(…) fn quux(x: i32) | ||
252 | "#]], | 284 | "#]], |
253 | ); | 285 | ); |
254 | } | 286 | } |
@@ -268,8 +300,8 @@ fn quux() { | |||
268 | } | 300 | } |
269 | "#, | 301 | "#, |
270 | expect![[r#" | 302 | expect![[r#" |
271 | bn a | ||
272 | bn b i32 | 303 | bn b i32 |
304 | bn a | ||
273 | fn quux() fn quux() | 305 | fn quux() fn quux() |
274 | "#]], | 306 | "#]], |
275 | ); | 307 | ); |
@@ -284,8 +316,8 @@ fn quux() { | |||
284 | } | 316 | } |
285 | "#, | 317 | "#, |
286 | expect![[r#" | 318 | expect![[r#" |
287 | fn quux() fn quux() | ||
288 | bn x | 319 | bn x |
320 | fn quux() fn quux() | ||
289 | "#]], | 321 | "#]], |
290 | ); | 322 | ); |
291 | } | 323 | } |
@@ -326,9 +358,9 @@ fn main() { | |||
326 | check( | 358 | check( |
327 | r#"struct S<T> { x: <|>}"#, | 359 | r#"struct S<T> { x: <|>}"#, |
328 | expect![[r#" | 360 | expect![[r#" |
329 | st S<…> | ||
330 | tp Self | 361 | tp Self |
331 | tp T | 362 | tp T |
363 | st S<…> | ||
332 | "#]], | 364 | "#]], |
333 | ); | 365 | ); |
334 | } | 366 | } |
@@ -353,9 +385,9 @@ enum E {} | |||
353 | fn quux() { <|> } | 385 | fn quux() { <|> } |
354 | "#, | 386 | "#, |
355 | expect![[r#" | 387 | expect![[r#" |
356 | en E | ||
357 | st S | 388 | st S |
358 | fn quux() fn quux() | 389 | fn quux() fn quux() |
390 | en E | ||
359 | "#]], | 391 | "#]], |
360 | ); | 392 | ); |
361 | } | 393 | } |
@@ -407,8 +439,8 @@ mod m { | |||
407 | } | 439 | } |
408 | "#, | 440 | "#, |
409 | expect![[r#" | 441 | expect![[r#" |
410 | st Bar | ||
411 | fn quux() fn quux() | 442 | fn quux() fn quux() |
443 | st Bar | ||
412 | "#]], | 444 | "#]], |
413 | ); | 445 | ); |
414 | } | 446 | } |
@@ -453,8 +485,8 @@ fn foo() { | |||
453 | check( | 485 | check( |
454 | r#"impl S { fn foo(&self) { <|> } }"#, | 486 | r#"impl S { fn foo(&self) { <|> } }"#, |
455 | expect![[r#" | 487 | expect![[r#" |
456 | tp Self | ||
457 | bn self &{unknown} | 488 | bn self &{unknown} |
489 | tp Self | ||
458 | "#]], | 490 | "#]], |
459 | ); | 491 | ); |
460 | } | 492 | } |
@@ -473,9 +505,9 @@ use prelude::*; | |||
473 | mod prelude { struct Option; } | 505 | mod prelude { struct Option; } |
474 | "#, | 506 | "#, |
475 | expect![[r#" | 507 | expect![[r#" |
476 | st Option | ||
477 | fn foo() fn foo() | 508 | fn foo() fn foo() |
478 | md std | 509 | md std |
510 | st Option | ||
479 | "#]], | 511 | "#]], |
480 | ); | 512 | ); |
481 | } | 513 | } |
@@ -500,10 +532,10 @@ use prelude::*; | |||
500 | mod prelude { struct String; } | 532 | mod prelude { struct String; } |
501 | "#, | 533 | "#, |
502 | expect![[r#" | 534 | expect![[r#" |
503 | st String | ||
504 | md core | ||
505 | fn foo() fn foo() | 535 | fn foo() fn foo() |
506 | md std | 536 | md std |
537 | md core | ||
538 | st String | ||
507 | "#]], | 539 | "#]], |
508 | ); | 540 | ); |
509 | } | 541 | } |
@@ -529,13 +561,13 @@ mod m2 { | |||
529 | fn main() { let v = <|> } | 561 | fn main() { let v = <|> } |
530 | "#, | 562 | "#, |
531 | expect![[r##" | 563 | expect![[r##" |
532 | ma bar!(…) macro_rules! bar | 564 | md m1 |
533 | ma baz!(…) #[macro_export] | 565 | ma baz!(…) #[macro_export] |
534 | macro_rules! baz | 566 | macro_rules! baz |
535 | ma foo!(…) macro_rules! foo | ||
536 | md m1 | ||
537 | md m2 | ||
538 | fn main() fn main() | 567 | fn main() fn main() |
568 | md m2 | ||
569 | ma bar!(…) macro_rules! bar | ||
570 | ma foo!(…) macro_rules! foo | ||
539 | "##]], | 571 | "##]], |
540 | ); | 572 | ); |
541 | } | 573 | } |
@@ -548,8 +580,8 @@ macro_rules! foo { () => {} } | |||
548 | fn foo() { <|> } | 580 | fn foo() { <|> } |
549 | "#, | 581 | "#, |
550 | expect![[r#" | 582 | expect![[r#" |
551 | ma foo!(…) macro_rules! foo | ||
552 | fn foo() fn foo() | 583 | fn foo() fn foo() |
584 | ma foo!(…) macro_rules! foo | ||
553 | "#]], | 585 | "#]], |
554 | ); | 586 | ); |
555 | } | 587 | } |
@@ -562,8 +594,8 @@ macro_rules! foo { () => {} } | |||
562 | fn main() { let x: <|> } | 594 | fn main() { let x: <|> } |
563 | "#, | 595 | "#, |
564 | expect![[r#" | 596 | expect![[r#" |
565 | ma foo!(…) macro_rules! foo | ||
566 | fn main() fn main() | 597 | fn main() fn main() |
598 | ma foo!(…) macro_rules! foo | ||
567 | "#]], | 599 | "#]], |
568 | ); | 600 | ); |
569 | } | 601 | } |
@@ -576,8 +608,8 @@ macro_rules! foo { () => {} } | |||
576 | fn main() { <|> } | 608 | fn main() { <|> } |
577 | "#, | 609 | "#, |
578 | expect![[r#" | 610 | expect![[r#" |
579 | ma foo!(…) macro_rules! foo | ||
580 | fn main() fn main() | 611 | fn main() fn main() |
612 | ma foo!(…) macro_rules! foo | ||
581 | "#]], | 613 | "#]], |
582 | ); | 614 | ); |
583 | } | 615 | } |
@@ -609,10 +641,10 @@ fn quux(x: i32) { | |||
609 | } | 641 | } |
610 | "#, | 642 | "#, |
611 | expect![[r#" | 643 | expect![[r#" |
612 | ma m!(…) macro_rules! m | ||
613 | fn quux(…) fn quux(x: i32) | ||
614 | bn x i32 | ||
615 | bn y i32 | 644 | bn y i32 |
645 | bn x i32 | ||
646 | fn quux(…) fn quux(x: i32) | ||
647 | ma m!(…) macro_rules! m | ||
616 | "#]], | 648 | "#]], |
617 | ); | 649 | ); |
618 | } | 650 | } |
@@ -628,10 +660,10 @@ fn quux(x: i32) { | |||
628 | } | 660 | } |
629 | ", | 661 | ", |
630 | expect![[r#" | 662 | expect![[r#" |
631 | ma m!(…) macro_rules! m | ||
632 | fn quux(…) fn quux(x: i32) | ||
633 | bn x i32 | ||
634 | bn y i32 | 663 | bn y i32 |
664 | bn x i32 | ||
665 | fn quux(…) fn quux(x: i32) | ||
666 | ma m!(…) macro_rules! m | ||
635 | "#]], | 667 | "#]], |
636 | ); | 668 | ); |
637 | } | 669 | } |
@@ -647,10 +679,10 @@ fn quux(x: i32) { | |||
647 | } | 679 | } |
648 | "#, | 680 | "#, |
649 | expect![[r#" | 681 | expect![[r#" |
650 | ma m!(…) macro_rules! m | ||
651 | fn quux(…) fn quux(x: i32) | ||
652 | bn x i32 | ||
653 | bn y i32 | 682 | bn y i32 |
683 | bn x i32 | ||
684 | fn quux(…) fn quux(x: i32) | ||
685 | ma m!(…) macro_rules! m | ||
654 | "#]], | 686 | "#]], |
655 | ); | 687 | ); |
656 | } | 688 | } |
@@ -664,8 +696,8 @@ use spam::Quux; | |||
664 | fn main() { <|> } | 696 | fn main() { <|> } |
665 | "#, | 697 | "#, |
666 | expect![[r#" | 698 | expect![[r#" |
667 | ?? Quux | ||
668 | fn main() fn main() | 699 | fn main() fn main() |
700 | ?? Quux | ||
669 | "#]], | 701 | "#]], |
670 | ); | 702 | ); |
671 | } | 703 | } |
@@ -681,10 +713,10 @@ fn main() { | |||
681 | } | 713 | } |
682 | "#, | 714 | "#, |
683 | expect![[r#" | 715 | expect![[r#" |
684 | en Foo | ||
685 | ev Foo::Bar () | 716 | ev Foo::Bar () |
686 | ev Foo::Baz () | 717 | ev Foo::Baz () |
687 | ev Foo::Quux () | 718 | ev Foo::Quux () |
719 | en Foo | ||
688 | "#]], | 720 | "#]], |
689 | ) | 721 | ) |
690 | } | 722 | } |
@@ -701,10 +733,10 @@ fn main() { | |||
701 | } | 733 | } |
702 | "#, | 734 | "#, |
703 | expect![[r#" | 735 | expect![[r#" |
704 | en Foo | ||
705 | ev Foo::Bar () | 736 | ev Foo::Bar () |
706 | ev Foo::Baz () | 737 | ev Foo::Baz () |
707 | ev Foo::Quux () | 738 | ev Foo::Quux () |
739 | en Foo | ||
708 | "#]], | 740 | "#]], |
709 | ) | 741 | ) |
710 | } | 742 | } |
@@ -717,10 +749,10 @@ enum Foo { Bar, Baz, Quux } | |||
717 | fn main() { let foo: Foo = Q<|> } | 749 | fn main() { let foo: Foo = Q<|> } |
718 | "#, | 750 | "#, |
719 | expect![[r#" | 751 | expect![[r#" |
720 | en Foo | ||
721 | ev Foo::Bar () | 752 | ev Foo::Bar () |
722 | ev Foo::Baz () | 753 | ev Foo::Baz () |
723 | ev Foo::Quux () | 754 | ev Foo::Quux () |
755 | en Foo | ||
724 | fn main() fn main() | 756 | fn main() fn main() |
725 | "#]], | 757 | "#]], |
726 | ) | 758 | ) |
@@ -734,9 +766,9 @@ mod m { pub enum E { V } } | |||
734 | fn f() -> m::E { V<|> } | 766 | fn f() -> m::E { V<|> } |
735 | "#, | 767 | "#, |
736 | expect![[r#" | 768 | expect![[r#" |
737 | fn f() fn f() -> m::E | ||
738 | md m | ||
739 | ev m::E::V () | 769 | ev m::E::V () |
770 | md m | ||
771 | fn f() fn f() -> m::E | ||
740 | "#]], | 772 | "#]], |
741 | ) | 773 | ) |
742 | } | 774 | } |
@@ -763,22 +795,17 @@ struct MyStruct {} | |||
763 | impl My<|> | 795 | impl My<|> |
764 | "#, | 796 | "#, |
765 | expect![[r#" | 797 | expect![[r#" |
766 | st MyStruct | ||
767 | tt MyTrait | ||
768 | tp Self | 798 | tp Self |
799 | tt MyTrait | ||
800 | st MyStruct | ||
769 | "#]], | 801 | "#]], |
770 | ) | 802 | ) |
771 | } | 803 | } |
772 | 804 | ||
773 | #[test] | 805 | #[test] |
774 | fn function_fuzzy_completion() { | 806 | fn function_fuzzy_completion() { |
775 | let mut completion_config = CompletionConfig::default(); | ||
776 | completion_config | ||
777 | .active_resolve_capabilities | ||
778 | .insert(crate::CompletionResolveCapability::AdditionalTextEdits); | ||
779 | |||
780 | check_edit_with_config( | 807 | check_edit_with_config( |
781 | completion_config, | 808 | fuzzy_completion_config(), |
782 | "stdin", | 809 | "stdin", |
783 | r#" | 810 | r#" |
784 | //- /lib.rs crate:dep | 811 | //- /lib.rs crate:dep |
@@ -803,13 +830,8 @@ fn main() { | |||
803 | 830 | ||
804 | #[test] | 831 | #[test] |
805 | fn macro_fuzzy_completion() { | 832 | fn macro_fuzzy_completion() { |
806 | let mut completion_config = CompletionConfig::default(); | ||
807 | completion_config | ||
808 | .active_resolve_capabilities | ||
809 | .insert(crate::CompletionResolveCapability::AdditionalTextEdits); | ||
810 | |||
811 | check_edit_with_config( | 833 | check_edit_with_config( |
812 | completion_config, | 834 | fuzzy_completion_config(), |
813 | "macro_with_curlies!", | 835 | "macro_with_curlies!", |
814 | r#" | 836 | r#" |
815 | //- /lib.rs crate:dep | 837 | //- /lib.rs crate:dep |
@@ -836,13 +858,8 @@ fn main() { | |||
836 | 858 | ||
837 | #[test] | 859 | #[test] |
838 | fn struct_fuzzy_completion() { | 860 | fn struct_fuzzy_completion() { |
839 | let mut completion_config = CompletionConfig::default(); | ||
840 | completion_config | ||
841 | .active_resolve_capabilities | ||
842 | .insert(crate::CompletionResolveCapability::AdditionalTextEdits); | ||
843 | |||
844 | check_edit_with_config( | 861 | check_edit_with_config( |
845 | completion_config, | 862 | fuzzy_completion_config(), |
846 | "ThirdStruct", | 863 | "ThirdStruct", |
847 | r#" | 864 | r#" |
848 | //- /lib.rs crate:dep | 865 | //- /lib.rs crate:dep |
@@ -868,4 +885,44 @@ fn main() { | |||
868 | "#, | 885 | "#, |
869 | ); | 886 | ); |
870 | } | 887 | } |
888 | |||
889 | #[test] | ||
890 | fn fuzzy_completions_come_in_specific_order() { | ||
891 | mark::check!(certain_fuzzy_order_test); | ||
892 | check_with_config( | ||
893 | fuzzy_completion_config(), | ||
894 | r#" | ||
895 | //- /lib.rs crate:dep | ||
896 | pub struct FirstStruct; | ||
897 | pub mod some_module { | ||
898 | // already imported, omitted | ||
899 | pub struct SecondStruct; | ||
900 | // does not contain all letters from the query, omitted | ||
901 | pub struct UnrelatedOne; | ||
902 | // contains all letters from the query, but not in sequence, displayed last | ||
903 | pub struct ThiiiiiirdStruct; | ||
904 | // contains all letters from the query, but not in the beginning, displayed second | ||
905 | pub struct AfterThirdStruct; | ||
906 | // contains all letters from the query in the begginning, displayed first | ||
907 | pub struct ThirdStruct; | ||
908 | } | ||
909 | |||
910 | //- /main.rs crate:main deps:dep | ||
911 | use dep::{FirstStruct, some_module::SecondStruct}; | ||
912 | |||
913 | fn main() { | ||
914 | hir<|> | ||
915 | } | ||
916 | "#, | ||
917 | expect![[r#" | ||
918 | fn main() fn main() | ||
919 | st SecondStruct | ||
920 | st FirstStruct | ||
921 | md dep | ||
922 | st dep::some_module::ThirdStruct | ||
923 | st dep::some_module::AfterThirdStruct | ||
924 | st dep::some_module::ThiiiiiirdStruct | ||
925 | "#]], | ||
926 | ); | ||
927 | } | ||
871 | } | 928 | } |
diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs index b940388df..1092a4825 100644 --- a/crates/completion/src/render.rs +++ b/crates/completion/src/render.rs | |||
@@ -19,7 +19,7 @@ use crate::{ | |||
19 | CompletionKind, CompletionScore, | 19 | CompletionKind, CompletionScore, |
20 | }; | 20 | }; |
21 | 21 | ||
22 | use crate::render::{enum_variant::render_enum_variant, function::render_fn, macro_::render_macro}; | 22 | use crate::render::{enum_variant::render_variant, function::render_fn, macro_::render_macro}; |
23 | 23 | ||
24 | pub(crate) fn render_field<'a>( | 24 | pub(crate) fn render_field<'a>( |
25 | ctx: RenderContext<'a>, | 25 | ctx: RenderContext<'a>, |
@@ -159,9 +159,8 @@ impl<'a> Render<'a> { | |||
159 | let item = render_fn(self.ctx, import_to_add, Some(local_name), *func); | 159 | let item = render_fn(self.ctx, import_to_add, Some(local_name), *func); |
160 | return Some(item); | 160 | return Some(item); |
161 | } | 161 | } |
162 | ScopeDef::ModuleDef(EnumVariant(var)) => { | 162 | ScopeDef::ModuleDef(Variant(var)) => { |
163 | let item = | 163 | let item = render_variant(self.ctx, import_to_add, Some(local_name), *var, None); |
164 | render_enum_variant(self.ctx, import_to_add, Some(local_name), *var, None); | ||
165 | return Some(item); | 164 | return Some(item); |
166 | } | 165 | } |
167 | ScopeDef::MacroDef(mac) => { | 166 | ScopeDef::MacroDef(mac) => { |
@@ -257,7 +256,7 @@ impl<'a> Render<'a> { | |||
257 | match resolution { | 256 | match resolution { |
258 | ScopeDef::ModuleDef(Module(it)) => it.docs(self.ctx.db()), | 257 | ScopeDef::ModuleDef(Module(it)) => it.docs(self.ctx.db()), |
259 | ScopeDef::ModuleDef(Adt(it)) => it.docs(self.ctx.db()), | 258 | ScopeDef::ModuleDef(Adt(it)) => it.docs(self.ctx.db()), |
260 | ScopeDef::ModuleDef(EnumVariant(it)) => it.docs(self.ctx.db()), | 259 | ScopeDef::ModuleDef(Variant(it)) => it.docs(self.ctx.db()), |
261 | ScopeDef::ModuleDef(Const(it)) => it.docs(self.ctx.db()), | 260 | ScopeDef::ModuleDef(Const(it)) => it.docs(self.ctx.db()), |
262 | ScopeDef::ModuleDef(Static(it)) => it.docs(self.ctx.db()), | 261 | ScopeDef::ModuleDef(Static(it)) => it.docs(self.ctx.db()), |
263 | ScopeDef::ModuleDef(Trait(it)) => it.docs(self.ctx.db()), | 262 | ScopeDef::ModuleDef(Trait(it)) => it.docs(self.ctx.db()), |
diff --git a/crates/completion/src/render/enum_variant.rs b/crates/completion/src/render/enum_variant.rs index 8e0fea6c0..7176fd9b3 100644 --- a/crates/completion/src/render/enum_variant.rs +++ b/crates/completion/src/render/enum_variant.rs | |||
@@ -9,35 +9,35 @@ use crate::{ | |||
9 | render::{builder_ext::Params, RenderContext}, | 9 | render::{builder_ext::Params, RenderContext}, |
10 | }; | 10 | }; |
11 | 11 | ||
12 | pub(crate) fn render_enum_variant<'a>( | 12 | pub(crate) fn render_variant<'a>( |
13 | ctx: RenderContext<'a>, | 13 | ctx: RenderContext<'a>, |
14 | import_to_add: Option<ImportEdit>, | 14 | import_to_add: Option<ImportEdit>, |
15 | local_name: Option<String>, | 15 | local_name: Option<String>, |
16 | variant: hir::EnumVariant, | 16 | variant: hir::Variant, |
17 | path: Option<ModPath>, | 17 | path: Option<ModPath>, |
18 | ) -> CompletionItem { | 18 | ) -> CompletionItem { |
19 | let _p = profile::span("render_enum_variant"); | 19 | let _p = profile::span("render_enum_variant"); |
20 | EnumVariantRender::new(ctx, local_name, variant, path).render(import_to_add) | 20 | EnumRender::new(ctx, local_name, variant, path).render(import_to_add) |
21 | } | 21 | } |
22 | 22 | ||
23 | #[derive(Debug)] | 23 | #[derive(Debug)] |
24 | struct EnumVariantRender<'a> { | 24 | struct EnumRender<'a> { |
25 | ctx: RenderContext<'a>, | 25 | ctx: RenderContext<'a>, |
26 | name: String, | 26 | name: String, |
27 | variant: hir::EnumVariant, | 27 | variant: hir::Variant, |
28 | path: Option<ModPath>, | 28 | path: Option<ModPath>, |
29 | qualified_name: String, | 29 | qualified_name: String, |
30 | short_qualified_name: String, | 30 | short_qualified_name: String, |
31 | variant_kind: StructKind, | 31 | variant_kind: StructKind, |
32 | } | 32 | } |
33 | 33 | ||
34 | impl<'a> EnumVariantRender<'a> { | 34 | impl<'a> EnumRender<'a> { |
35 | fn new( | 35 | fn new( |
36 | ctx: RenderContext<'a>, | 36 | ctx: RenderContext<'a>, |
37 | local_name: Option<String>, | 37 | local_name: Option<String>, |
38 | variant: hir::EnumVariant, | 38 | variant: hir::Variant, |
39 | path: Option<ModPath>, | 39 | path: Option<ModPath>, |
40 | ) -> EnumVariantRender<'a> { | 40 | ) -> EnumRender<'a> { |
41 | let name = local_name.unwrap_or_else(|| variant.name(ctx.db()).to_string()); | 41 | let name = local_name.unwrap_or_else(|| variant.name(ctx.db()).to_string()); |
42 | let variant_kind = variant.kind(ctx.db()); | 42 | let variant_kind = variant.kind(ctx.db()); |
43 | 43 | ||
@@ -51,15 +51,7 @@ impl<'a> EnumVariantRender<'a> { | |||
51 | None => (name.to_string(), name.to_string()), | 51 | None => (name.to_string(), name.to_string()), |
52 | }; | 52 | }; |
53 | 53 | ||
54 | EnumVariantRender { | 54 | EnumRender { ctx, name, variant, path, qualified_name, short_qualified_name, variant_kind } |
55 | ctx, | ||
56 | name, | ||
57 | variant, | ||
58 | path, | ||
59 | qualified_name, | ||
60 | short_qualified_name, | ||
61 | variant_kind, | ||
62 | } | ||
63 | } | 55 | } |
64 | 56 | ||
65 | fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem { | 57 | fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem { |
diff --git a/crates/completion/src/render/macro_.rs b/crates/completion/src/render/macro_.rs index 6cfbd6c9b..dac79592f 100644 --- a/crates/completion/src/render/macro_.rs +++ b/crates/completion/src/render/macro_.rs | |||
@@ -41,6 +41,7 @@ impl<'a> MacroRender<'a> { | |||
41 | fn render(&self, import_to_add: Option<ImportEdit>) -> Option<CompletionItem> { | 41 | fn render(&self, import_to_add: Option<ImportEdit>) -> Option<CompletionItem> { |
42 | // FIXME: Currently proc-macro do not have ast-node, | 42 | // FIXME: Currently proc-macro do not have ast-node, |
43 | // such that it does not have source | 43 | // such that it does not have source |
44 | // more discussion: https://github.com/rust-analyzer/rust-analyzer/issues/6913 | ||
44 | if self.macro_.is_proc_macro() { | 45 | if self.macro_.is_proc_macro() { |
45 | return None; | 46 | return None; |
46 | } | 47 | } |
diff --git a/crates/completion/src/test_utils.rs b/crates/completion/src/test_utils.rs index db896b2df..eb0c16f52 100644 --- a/crates/completion/src/test_utils.rs +++ b/crates/completion/src/test_utils.rs | |||
@@ -47,9 +47,8 @@ pub(crate) fn completion_list_with_config( | |||
47 | code: &str, | 47 | code: &str, |
48 | kind: CompletionKind, | 48 | kind: CompletionKind, |
49 | ) -> String { | 49 | ) -> String { |
50 | let mut kind_completions: Vec<CompletionItem> = | 50 | let kind_completions: Vec<CompletionItem> = |
51 | get_all_items(config, code).into_iter().filter(|c| c.completion_kind == kind).collect(); | 51 | get_all_items(config, code).into_iter().filter(|c| c.completion_kind == kind).collect(); |
52 | kind_completions.sort_by_key(|c| c.label().to_owned()); | ||
53 | let label_width = kind_completions | 52 | let label_width = kind_completions |
54 | .iter() | 53 | .iter() |
55 | .map(|it| monospace_width(it.label())) | 54 | .map(|it| monospace_width(it.label())) |