diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/dot.rs | 24 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/flyimport.rs | 8 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/qualified_path.rs | 56 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/unqualified_path.rs | 50 | ||||
-rw-r--r-- | crates/ide_completion/src/lib.rs | 6 | ||||
-rw-r--r-- | crates/ide_completion/src/render.rs | 54 | ||||
-rw-r--r-- | crates/ide_completion/src/render/function.rs | 31 |
8 files changed, 155 insertions, 82 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 58adc8fd3..8d082994a 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -921,6 +921,14 @@ impl SelfParam { | |||
921 | }) | 921 | }) |
922 | .unwrap_or(Access::Owned) | 922 | .unwrap_or(Access::Owned) |
923 | } | 923 | } |
924 | |||
925 | pub fn display(self, db: &dyn HirDatabase) -> &'static str { | ||
926 | match self.access(db) { | ||
927 | Access::Shared => "&self", | ||
928 | Access::Exclusive => "&mut self", | ||
929 | Access::Owned => "self", | ||
930 | } | ||
931 | } | ||
924 | } | 932 | } |
925 | 933 | ||
926 | impl HasVisibility for Function { | 934 | impl HasVisibility for Function { |
diff --git a/crates/ide_completion/src/completions/dot.rs b/crates/ide_completion/src/completions/dot.rs index 5ee9a9f07..cec2d0c3a 100644 --- a/crates/ide_completion/src/completions/dot.rs +++ b/crates/ide_completion/src/completions/dot.rs | |||
@@ -81,7 +81,7 @@ fn foo(s: S) { s.$0 } | |||
81 | "#, | 81 | "#, |
82 | expect![[r#" | 82 | expect![[r#" |
83 | fd foo u32 | 83 | fd foo u32 |
84 | me bar() -> () | 84 | me bar() fn(&self) |
85 | "#]], | 85 | "#]], |
86 | ); | 86 | ); |
87 | } | 87 | } |
@@ -97,7 +97,7 @@ impl S { | |||
97 | "#, | 97 | "#, |
98 | expect![[r#" | 98 | expect![[r#" |
99 | fd the_field (u32,) | 99 | fd the_field (u32,) |
100 | me foo() -> () | 100 | me foo() fn(self) |
101 | "#]], | 101 | "#]], |
102 | ) | 102 | ) |
103 | } | 103 | } |
@@ -113,7 +113,7 @@ impl A { | |||
113 | "#, | 113 | "#, |
114 | expect![[r#" | 114 | expect![[r#" |
115 | fd the_field (u32, i32) | 115 | fd the_field (u32, i32) |
116 | me foo() -> () | 116 | me foo() fn(&self) |
117 | "#]], | 117 | "#]], |
118 | ) | 118 | ) |
119 | } | 119 | } |
@@ -163,7 +163,7 @@ mod m { | |||
163 | fn foo(a: A) { a.$0 } | 163 | fn foo(a: A) { a.$0 } |
164 | "#, | 164 | "#, |
165 | expect![[r#" | 165 | expect![[r#" |
166 | me the_method() -> () | 166 | me the_method() fn(&self) |
167 | "#]], | 167 | "#]], |
168 | ); | 168 | ); |
169 | } | 169 | } |
@@ -196,7 +196,7 @@ impl A<i32> { | |||
196 | fn foo(a: A<u32>) { a.$0 } | 196 | fn foo(a: A<u32>) { a.$0 } |
197 | "#, | 197 | "#, |
198 | expect![[r#" | 198 | expect![[r#" |
199 | me the_method() -> () | 199 | me the_method() fn(&self) |
200 | "#]], | 200 | "#]], |
201 | ) | 201 | ) |
202 | } | 202 | } |
@@ -211,7 +211,7 @@ impl Trait for A {} | |||
211 | fn foo(a: A) { a.$0 } | 211 | fn foo(a: A) { a.$0 } |
212 | "#, | 212 | "#, |
213 | expect![[r#" | 213 | expect![[r#" |
214 | me the_method() -> () | 214 | me the_method() fn(&self) |
215 | "#]], | 215 | "#]], |
216 | ); | 216 | ); |
217 | } | 217 | } |
@@ -226,7 +226,7 @@ impl<T> Trait for T {} | |||
226 | fn foo(a: &A) { a.$0 } | 226 | fn foo(a: &A) { a.$0 } |
227 | ", | 227 | ", |
228 | expect![[r#" | 228 | expect![[r#" |
229 | me the_method() -> () | 229 | me the_method() fn(&self) |
230 | "#]], | 230 | "#]], |
231 | ); | 231 | ); |
232 | } | 232 | } |
@@ -244,7 +244,7 @@ impl Trait for A {} | |||
244 | fn foo(a: A) { a.$0 } | 244 | fn foo(a: A) { a.$0 } |
245 | ", | 245 | ", |
246 | expect![[r#" | 246 | expect![[r#" |
247 | me the_method() -> () | 247 | me the_method() fn(&self) |
248 | "#]], | 248 | "#]], |
249 | ); | 249 | ); |
250 | } | 250 | } |
@@ -298,7 +298,7 @@ impl T { | |||
298 | } | 298 | } |
299 | "#, | 299 | "#, |
300 | expect![[r#" | 300 | expect![[r#" |
301 | me blah() -> () | 301 | me blah() fn(&self) |
302 | "#]], | 302 | "#]], |
303 | ); | 303 | ); |
304 | } | 304 | } |
@@ -407,7 +407,7 @@ fn foo() { | |||
407 | } | 407 | } |
408 | "#, | 408 | "#, |
409 | expect![[r#" | 409 | expect![[r#" |
410 | me the_method() -> () | 410 | me the_method() fn(&self) |
411 | "#]], | 411 | "#]], |
412 | ); | 412 | ); |
413 | } | 413 | } |
@@ -422,7 +422,7 @@ macro_rules! make_s { () => { S }; } | |||
422 | fn main() { make_s!().f$0; } | 422 | fn main() { make_s!().f$0; } |
423 | "#, | 423 | "#, |
424 | expect![[r#" | 424 | expect![[r#" |
425 | me foo() -> () | 425 | me foo() fn(&self) |
426 | "#]], | 426 | "#]], |
427 | ) | 427 | ) |
428 | } | 428 | } |
@@ -450,7 +450,7 @@ mod foo { | |||
450 | } | 450 | } |
451 | "#, | 451 | "#, |
452 | expect![[r#" | 452 | expect![[r#" |
453 | me private() -> () | 453 | me private() fn(&self) |
454 | "#]], | 454 | "#]], |
455 | ); | 455 | ); |
456 | } | 456 | } |
diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index 391a11c91..08df2df3f 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs | |||
@@ -402,7 +402,7 @@ fn main() { | |||
402 | check( | 402 | check( |
403 | fixture, | 403 | fixture, |
404 | expect![[r#" | 404 | expect![[r#" |
405 | fn weird_function() (dep::test_mod::TestTrait) -> () | 405 | fn weird_function() (dep::test_mod::TestTrait) fn() |
406 | "#]], | 406 | "#]], |
407 | ); | 407 | ); |
408 | 408 | ||
@@ -495,7 +495,7 @@ fn main() { | |||
495 | check( | 495 | check( |
496 | fixture, | 496 | fixture, |
497 | expect![[r#" | 497 | expect![[r#" |
498 | me random_method() (dep::test_mod::TestTrait) -> () | 498 | me random_method() (dep::test_mod::TestTrait) fn(&self) |
499 | "#]], | 499 | "#]], |
500 | ); | 500 | ); |
501 | 501 | ||
@@ -665,7 +665,7 @@ fn main() { | |||
665 | } | 665 | } |
666 | "#, | 666 | "#, |
667 | expect![[r#" | 667 | expect![[r#" |
668 | me random_method() (dep::test_mod::TestTrait) -> () DEPRECATED | 668 | me random_method() (dep::test_mod::TestTrait) fn(&self) DEPRECATED |
669 | "#]], | 669 | "#]], |
670 | ); | 670 | ); |
671 | 671 | ||
@@ -696,7 +696,7 @@ fn main() { | |||
696 | "#, | 696 | "#, |
697 | expect![[r#" | 697 | expect![[r#" |
698 | ct SPECIAL_CONST (dep::test_mod::TestTrait) DEPRECATED | 698 | ct SPECIAL_CONST (dep::test_mod::TestTrait) DEPRECATED |
699 | fn weird_function() (dep::test_mod::TestTrait) -> () DEPRECATED | 699 | fn weird_function() (dep::test_mod::TestTrait) fn() DEPRECATED |
700 | "#]], | 700 | "#]], |
701 | ); | 701 | ); |
702 | } | 702 | } |
diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs index df74b739e..105ff6013 100644 --- a/crates/ide_completion/src/completions/qualified_path.rs +++ b/crates/ide_completion/src/completions/qualified_path.rs | |||
@@ -359,8 +359,8 @@ impl S { | |||
359 | fn foo() { let _ = S::$0 } | 359 | fn foo() { let _ = S::$0 } |
360 | "#, | 360 | "#, |
361 | expect![[r#" | 361 | expect![[r#" |
362 | fn a() -> () | 362 | fn a() fn() |
363 | me b(…) -> () | 363 | me b(…) fn(&self) |
364 | ct C const C: i32 = 42; | 364 | ct C const C: i32 = 42; |
365 | ta T type T = i32; | 365 | ta T type T = i32; |
366 | "#]], | 366 | "#]], |
@@ -387,7 +387,7 @@ mod m { | |||
387 | fn foo() { let _ = S::$0 } | 387 | fn foo() { let _ = S::$0 } |
388 | "#, | 388 | "#, |
389 | expect![[r#" | 389 | expect![[r#" |
390 | fn public_method() -> () | 390 | fn public_method() fn() |
391 | ct PUBLIC_CONST pub(crate) const PUBLIC_CONST: u32 = 1; | 391 | ct PUBLIC_CONST pub(crate) const PUBLIC_CONST: u32 = 1; |
392 | ta PublicType pub(crate) type PublicType = u32; | 392 | ta PublicType pub(crate) type PublicType = u32; |
393 | "#]], | 393 | "#]], |
@@ -404,7 +404,7 @@ impl E { fn m() { } } | |||
404 | fn foo() { let _ = E::$0 } | 404 | fn foo() { let _ = E::$0 } |
405 | "#, | 405 | "#, |
406 | expect![[r#" | 406 | expect![[r#" |
407 | fn m() -> () | 407 | fn m() fn() |
408 | "#]], | 408 | "#]], |
409 | ); | 409 | ); |
410 | } | 410 | } |
@@ -419,7 +419,7 @@ impl U { fn m() { } } | |||
419 | fn foo() { let _ = U::$0 } | 419 | fn foo() { let _ = U::$0 } |
420 | "#, | 420 | "#, |
421 | expect![[r#" | 421 | expect![[r#" |
422 | fn m() -> () | 422 | fn m() fn() |
423 | "#]], | 423 | "#]], |
424 | ); | 424 | ); |
425 | } | 425 | } |
@@ -449,7 +449,7 @@ trait Trait { fn m(); } | |||
449 | fn foo() { let _ = Trait::$0 } | 449 | fn foo() { let _ = Trait::$0 } |
450 | "#, | 450 | "#, |
451 | expect![[r#" | 451 | expect![[r#" |
452 | fn m() -> () | 452 | fn m() fn() |
453 | "#]], | 453 | "#]], |
454 | ); | 454 | ); |
455 | } | 455 | } |
@@ -466,7 +466,7 @@ impl Trait for S {} | |||
466 | fn foo() { let _ = S::$0 } | 466 | fn foo() { let _ = S::$0 } |
467 | "#, | 467 | "#, |
468 | expect![[r#" | 468 | expect![[r#" |
469 | fn m() -> () | 469 | fn m() fn() |
470 | "#]], | 470 | "#]], |
471 | ); | 471 | ); |
472 | } | 472 | } |
@@ -483,7 +483,7 @@ impl Trait for S {} | |||
483 | fn foo() { let _ = <S as Trait>::$0 } | 483 | fn foo() { let _ = <S as Trait>::$0 } |
484 | "#, | 484 | "#, |
485 | expect![[r#" | 485 | expect![[r#" |
486 | fn m() -> () | 486 | fn m() fn() |
487 | "#]], | 487 | "#]], |
488 | ); | 488 | ); |
489 | } | 489 | } |
@@ -512,11 +512,11 @@ fn foo<T: Sub>() { T::$0 } | |||
512 | ta SubTy type SubTy; | 512 | ta SubTy type SubTy; |
513 | ta Ty type Ty; | 513 | ta Ty type Ty; |
514 | ct C2 const C2: (); | 514 | ct C2 const C2: (); |
515 | fn subfunc() -> () | 515 | fn subfunc() fn() |
516 | me submethod(…) -> () | 516 | me submethod(…) fn(&self) |
517 | ct CONST const CONST: u8; | 517 | ct CONST const CONST: u8; |
518 | fn func() -> () | 518 | fn func() fn() |
519 | me method(…) -> () | 519 | me method(…) fn(&self) |
520 | "#]], | 520 | "#]], |
521 | ); | 521 | ); |
522 | } | 522 | } |
@@ -552,11 +552,11 @@ impl<T> Sub for Wrap<T> { | |||
552 | ta SubTy type SubTy; | 552 | ta SubTy type SubTy; |
553 | ta Ty type Ty; | 553 | ta Ty type Ty; |
554 | ct CONST const CONST: u8 = 0; | 554 | ct CONST const CONST: u8 = 0; |
555 | fn func() -> () | 555 | fn func() fn() |
556 | me method(…) -> () | 556 | me method(…) fn(&self) |
557 | ct C2 const C2: () = (); | 557 | ct C2 const C2: () = (); |
558 | fn subfunc() -> () | 558 | fn subfunc() fn() |
559 | me submethod(…) -> () | 559 | me submethod(…) fn(&self) |
560 | "#]], | 560 | "#]], |
561 | ); | 561 | ); |
562 | } | 562 | } |
@@ -573,8 +573,8 @@ impl T { fn bar() {} } | |||
573 | fn main() { T::$0; } | 573 | fn main() { T::$0; } |
574 | "#, | 574 | "#, |
575 | expect![[r#" | 575 | expect![[r#" |
576 | fn foo() -> () | 576 | fn foo() fn() |
577 | fn bar() -> () | 577 | fn bar() fn() |
578 | "#]], | 578 | "#]], |
579 | ); | 579 | ); |
580 | } | 580 | } |
@@ -589,7 +589,7 @@ macro_rules! foo { () => {} } | |||
589 | fn main() { let _ = crate::$0 } | 589 | fn main() { let _ = crate::$0 } |
590 | "#, | 590 | "#, |
591 | expect![[r##" | 591 | expect![[r##" |
592 | fn main() -> () | 592 | fn main() fn() |
593 | ma foo!(…) #[macro_export] macro_rules! foo | 593 | ma foo!(…) #[macro_export] macro_rules! foo |
594 | "##]], | 594 | "##]], |
595 | ); | 595 | ); |
@@ -633,7 +633,7 @@ mod p { | |||
633 | "#, | 633 | "#, |
634 | expect![[r#" | 634 | expect![[r#" |
635 | ct RIGHT_CONST | 635 | ct RIGHT_CONST |
636 | fn right_fn() -> () | 636 | fn right_fn() fn() |
637 | st RightType | 637 | st RightType |
638 | "#]], | 638 | "#]], |
639 | ); | 639 | ); |
@@ -680,8 +680,8 @@ fn main() { m!(self::f$0); } | |||
680 | fn foo() {} | 680 | fn foo() {} |
681 | "#, | 681 | "#, |
682 | expect![[r#" | 682 | expect![[r#" |
683 | fn main() -> () | 683 | fn main() fn() |
684 | fn foo() -> () | 684 | fn foo() fn() |
685 | "#]], | 685 | "#]], |
686 | ); | 686 | ); |
687 | } | 687 | } |
@@ -699,7 +699,7 @@ mod m { | |||
699 | "#, | 699 | "#, |
700 | expect![[r#" | 700 | expect![[r#" |
701 | md z | 701 | md z |
702 | fn z() -> () | 702 | fn z() fn() |
703 | "#]], | 703 | "#]], |
704 | ); | 704 | ); |
705 | } | 705 | } |
@@ -719,7 +719,7 @@ fn foo() { | |||
719 | } | 719 | } |
720 | "#, | 720 | "#, |
721 | expect![[r#" | 721 | expect![[r#" |
722 | fn new() -> HashMap<K, V, RandomState> | 722 | fn new() fn() -> HashMap<K, V, RandomState> |
723 | "#]], | 723 | "#]], |
724 | ); | 724 | ); |
725 | } | 725 | } |
@@ -752,8 +752,8 @@ fn main() { | |||
752 | } | 752 | } |
753 | "#, | 753 | "#, |
754 | expect![[r#" | 754 | expect![[r#" |
755 | fn main() -> () | 755 | fn main() fn() |
756 | fn foo(…) -> () | 756 | fn foo(…) fn(i32, i32) |
757 | "#]], | 757 | "#]], |
758 | ); | 758 | ); |
759 | } | 759 | } |
@@ -776,7 +776,7 @@ impl Foo { | |||
776 | expect![[r#" | 776 | expect![[r#" |
777 | ev Bar () | 777 | ev Bar () |
778 | ev Baz () | 778 | ev Baz () |
779 | me foo(…) -> () | 779 | me foo(…) fn(self) |
780 | "#]], | 780 | "#]], |
781 | ); | 781 | ); |
782 | } | 782 | } |
@@ -800,7 +800,7 @@ impl u8 { | |||
800 | "#, | 800 | "#, |
801 | expect![[r#" | 801 | expect![[r#" |
802 | ct MAX pub const MAX: Self = 255; | 802 | ct MAX pub const MAX: Self = 255; |
803 | me func(…) -> () | 803 | me func(…) fn(self) |
804 | "#]], | 804 | "#]], |
805 | ); | 805 | ); |
806 | } | 806 | } |
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index 044dfd160..e4bf4a043 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs | |||
@@ -139,7 +139,7 @@ fn quux(x: i32) { | |||
139 | expect![[r#" | 139 | expect![[r#" |
140 | lc y i32 | 140 | lc y i32 |
141 | lc x i32 | 141 | lc x i32 |
142 | fn quux(…) -> () | 142 | fn quux(…) fn(i32) |
143 | "#]], | 143 | "#]], |
144 | ); | 144 | ); |
145 | } | 145 | } |
@@ -161,7 +161,7 @@ fn quux() { | |||
161 | expect![[r#" | 161 | expect![[r#" |
162 | lc b i32 | 162 | lc b i32 |
163 | lc a | 163 | lc a |
164 | fn quux() -> () | 164 | fn quux() fn() |
165 | "#]], | 165 | "#]], |
166 | ); | 166 | ); |
167 | } | 167 | } |
@@ -176,7 +176,7 @@ fn quux() { | |||
176 | "#, | 176 | "#, |
177 | expect![[r#" | 177 | expect![[r#" |
178 | lc x | 178 | lc x |
179 | fn quux() -> () | 179 | fn quux() fn() |
180 | "#]], | 180 | "#]], |
181 | ); | 181 | ); |
182 | } | 182 | } |
@@ -207,14 +207,14 @@ fn main() { | |||
207 | r#"fn quux<T>() { $0 }"#, | 207 | r#"fn quux<T>() { $0 }"#, |
208 | expect![[r#" | 208 | expect![[r#" |
209 | tp T | 209 | tp T |
210 | fn quux() -> () | 210 | fn quux() fn() |
211 | "#]], | 211 | "#]], |
212 | ); | 212 | ); |
213 | check( | 213 | check( |
214 | r#"fn quux<const C: usize>() { $0 }"#, | 214 | r#"fn quux<const C: usize>() { $0 }"#, |
215 | expect![[r#" | 215 | expect![[r#" |
216 | cp C | 216 | cp C |
217 | fn quux() -> () | 217 | fn quux() fn() |
218 | "#]], | 218 | "#]], |
219 | ); | 219 | ); |
220 | } | 220 | } |
@@ -225,7 +225,7 @@ fn main() { | |||
225 | check( | 225 | check( |
226 | r#"fn quux<'a>() { $0 }"#, | 226 | r#"fn quux<'a>() { $0 }"#, |
227 | expect![[r#" | 227 | expect![[r#" |
228 | fn quux() -> () | 228 | fn quux() fn() |
229 | "#]], | 229 | "#]], |
230 | ); | 230 | ); |
231 | } | 231 | } |
@@ -263,7 +263,7 @@ fn quux() { $0 } | |||
263 | "#, | 263 | "#, |
264 | expect![[r#" | 264 | expect![[r#" |
265 | st S | 265 | st S |
266 | fn quux() -> () | 266 | fn quux() fn() |
267 | en E | 267 | en E |
268 | "#]], | 268 | "#]], |
269 | ); | 269 | ); |
@@ -316,7 +316,7 @@ mod m { | |||
316 | } | 316 | } |
317 | "#, | 317 | "#, |
318 | expect![[r#" | 318 | expect![[r#" |
319 | fn quux() -> () | 319 | fn quux() fn() |
320 | st Bar | 320 | st Bar |
321 | "#]], | 321 | "#]], |
322 | ); | 322 | ); |
@@ -331,7 +331,7 @@ fn x() -> $0 | |||
331 | "#, | 331 | "#, |
332 | expect![[r#" | 332 | expect![[r#" |
333 | st Foo | 333 | st Foo |
334 | fn x() -> () | 334 | fn x() fn() |
335 | "#]], | 335 | "#]], |
336 | ); | 336 | ); |
337 | } | 337 | } |
@@ -352,7 +352,7 @@ fn foo() { | |||
352 | expect![[r#" | 352 | expect![[r#" |
353 | lc bar i32 | 353 | lc bar i32 |
354 | lc bar i32 | 354 | lc bar i32 |
355 | fn foo() -> () | 355 | fn foo() fn() |
356 | "#]], | 356 | "#]], |
357 | ); | 357 | ); |
358 | } | 358 | } |
@@ -382,7 +382,7 @@ use prelude::*; | |||
382 | mod prelude { struct Option; } | 382 | mod prelude { struct Option; } |
383 | "#, | 383 | "#, |
384 | expect![[r#" | 384 | expect![[r#" |
385 | fn foo() -> () | 385 | fn foo() fn() |
386 | md std | 386 | md std |
387 | st Option | 387 | st Option |
388 | "#]], | 388 | "#]], |
@@ -412,7 +412,7 @@ mod macros { | |||
412 | } | 412 | } |
413 | "#, | 413 | "#, |
414 | expect![[r##" | 414 | expect![[r##" |
415 | fn f() -> () | 415 | fn f() fn() |
416 | ma concat!(…) #[macro_export] macro_rules! concat | 416 | ma concat!(…) #[macro_export] macro_rules! concat |
417 | md std | 417 | md std |
418 | "##]], | 418 | "##]], |
@@ -439,7 +439,7 @@ use prelude::*; | |||
439 | mod prelude { struct String; } | 439 | mod prelude { struct String; } |
440 | "#, | 440 | "#, |
441 | expect![[r#" | 441 | expect![[r#" |
442 | fn foo() -> () | 442 | fn foo() fn() |
443 | md std | 443 | md std |
444 | md core | 444 | md core |
445 | st String | 445 | st String |
@@ -470,7 +470,7 @@ fn main() { let v = $0 } | |||
470 | expect![[r##" | 470 | expect![[r##" |
471 | md m1 | 471 | md m1 |
472 | ma baz!(…) #[macro_export] macro_rules! baz | 472 | ma baz!(…) #[macro_export] macro_rules! baz |
473 | fn main() -> () | 473 | fn main() fn() |
474 | md m2 | 474 | md m2 |
475 | ma bar!(…) macro_rules! bar | 475 | ma bar!(…) macro_rules! bar |
476 | ma foo!(…) macro_rules! foo | 476 | ma foo!(…) macro_rules! foo |
@@ -486,7 +486,7 @@ macro_rules! foo { () => {} } | |||
486 | fn foo() { $0 } | 486 | fn foo() { $0 } |
487 | "#, | 487 | "#, |
488 | expect![[r#" | 488 | expect![[r#" |
489 | fn foo() -> () | 489 | fn foo() fn() |
490 | ma foo!(…) macro_rules! foo | 490 | ma foo!(…) macro_rules! foo |
491 | "#]], | 491 | "#]], |
492 | ); | 492 | ); |
@@ -500,7 +500,7 @@ macro_rules! foo { () => {} } | |||
500 | fn main() { let x: $0 } | 500 | fn main() { let x: $0 } |
501 | "#, | 501 | "#, |
502 | expect![[r#" | 502 | expect![[r#" |
503 | fn main() -> () | 503 | fn main() fn() |
504 | ma foo!(…) macro_rules! foo | 504 | ma foo!(…) macro_rules! foo |
505 | "#]], | 505 | "#]], |
506 | ); | 506 | ); |
@@ -514,7 +514,7 @@ macro_rules! foo { () => {} } | |||
514 | fn main() { $0 } | 514 | fn main() { $0 } |
515 | "#, | 515 | "#, |
516 | expect![[r#" | 516 | expect![[r#" |
517 | fn main() -> () | 517 | fn main() fn() |
518 | ma foo!(…) macro_rules! foo | 518 | ma foo!(…) macro_rules! foo |
519 | "#]], | 519 | "#]], |
520 | ); | 520 | ); |
@@ -530,8 +530,8 @@ fn main() { | |||
530 | } | 530 | } |
531 | "#, | 531 | "#, |
532 | expect![[r#" | 532 | expect![[r#" |
533 | fn frobnicate() -> () | 533 | fn frobnicate() fn() |
534 | fn main() -> () | 534 | fn main() fn() |
535 | "#]], | 535 | "#]], |
536 | ); | 536 | ); |
537 | } | 537 | } |
@@ -549,7 +549,7 @@ fn quux(x: i32) { | |||
549 | expect![[r#" | 549 | expect![[r#" |
550 | lc y i32 | 550 | lc y i32 |
551 | lc x i32 | 551 | lc x i32 |
552 | fn quux(…) -> () | 552 | fn quux(…) fn(i32) |
553 | ma m!(…) macro_rules! m | 553 | ma m!(…) macro_rules! m |
554 | "#]], | 554 | "#]], |
555 | ); | 555 | ); |
@@ -568,7 +568,7 @@ fn quux(x: i32) { | |||
568 | expect![[r#" | 568 | expect![[r#" |
569 | lc y i32 | 569 | lc y i32 |
570 | lc x i32 | 570 | lc x i32 |
571 | fn quux(…) -> () | 571 | fn quux(…) fn(i32) |
572 | ma m!(…) macro_rules! m | 572 | ma m!(…) macro_rules! m |
573 | "#]], | 573 | "#]], |
574 | ); | 574 | ); |
@@ -587,7 +587,7 @@ fn quux(x: i32) { | |||
587 | expect![[r#" | 587 | expect![[r#" |
588 | lc y i32 | 588 | lc y i32 |
589 | lc x i32 | 589 | lc x i32 |
590 | fn quux(…) -> () | 590 | fn quux(…) fn(i32) |
591 | ma m!(…) macro_rules! m | 591 | ma m!(…) macro_rules! m |
592 | "#]], | 592 | "#]], |
593 | ); | 593 | ); |
@@ -602,7 +602,7 @@ use spam::Quux; | |||
602 | fn main() { $0 } | 602 | fn main() { $0 } |
603 | "#, | 603 | "#, |
604 | expect![[r#" | 604 | expect![[r#" |
605 | fn main() -> () | 605 | fn main() fn() |
606 | ?? Quux | 606 | ?? Quux |
607 | "#]], | 607 | "#]], |
608 | ); | 608 | ); |
@@ -680,7 +680,7 @@ fn main() { let foo: Foo = Q$0 } | |||
680 | ev Foo::Baz () | 680 | ev Foo::Baz () |
681 | ev Foo::Quux () | 681 | ev Foo::Quux () |
682 | en Foo | 682 | en Foo |
683 | fn main() -> () | 683 | fn main() fn() |
684 | "#]], | 684 | "#]], |
685 | ) | 685 | ) |
686 | } | 686 | } |
@@ -695,7 +695,7 @@ fn f() -> m::E { V$0 } | |||
695 | expect![[r#" | 695 | expect![[r#" |
696 | ev m::E::V () | 696 | ev m::E::V () |
697 | md m | 697 | md m |
698 | fn f() -> E | 698 | fn f() fn() -> E |
699 | "#]], | 699 | "#]], |
700 | ) | 700 | ) |
701 | } | 701 | } |
diff --git a/crates/ide_completion/src/lib.rs b/crates/ide_completion/src/lib.rs index 263554ecf..5b7ad38d5 100644 --- a/crates/ide_completion/src/lib.rs +++ b/crates/ide_completion/src/lib.rs | |||
@@ -230,7 +230,7 @@ fn foo() { | |||
230 | bar.fo$0; | 230 | bar.fo$0; |
231 | } | 231 | } |
232 | "#, | 232 | "#, |
233 | DetailAndDocumentation { detail: "-> ()", documentation: "Do the foo" }, | 233 | DetailAndDocumentation { detail: "fn(&self)", documentation: "Do the foo" }, |
234 | ); | 234 | ); |
235 | } | 235 | } |
236 | 236 | ||
@@ -255,7 +255,7 @@ fn foo() { | |||
255 | bar.fo$0; | 255 | bar.fo$0; |
256 | } | 256 | } |
257 | "#, | 257 | "#, |
258 | DetailAndDocumentation { detail: "-> ()", documentation: " Do the foo" }, | 258 | DetailAndDocumentation { detail: "fn(&self)", documentation: " Do the foo" }, |
259 | ); | 259 | ); |
260 | } | 260 | } |
261 | 261 | ||
@@ -273,7 +273,7 @@ fn bar() { | |||
273 | for c in fo$0 | 273 | for c in fo$0 |
274 | } | 274 | } |
275 | "#, | 275 | "#, |
276 | DetailAndDocumentation { detail: "-> &str", documentation: "Do the foo" }, | 276 | DetailAndDocumentation { detail: "fn() -> &str", documentation: "Do the foo" }, |
277 | ); | 277 | ); |
278 | } | 278 | } |
279 | } | 279 | } |
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs index db31896e5..d9bf52582 100644 --- a/crates/ide_completion/src/render.rs +++ b/crates/ide_completion/src/render.rs | |||
@@ -425,6 +425,44 @@ fn main() { Foo::Fo$0 } | |||
425 | } | 425 | } |
426 | 426 | ||
427 | #[test] | 427 | #[test] |
428 | fn fn_detail_includes_args_and_return_type() { | ||
429 | check( | ||
430 | r#" | ||
431 | fn foo<T>(a: u32, b: u32, t: T) -> (u32, T) { (a, t) } | ||
432 | |||
433 | fn main() { fo$0 } | ||
434 | "#, | ||
435 | expect![[r#" | ||
436 | [ | ||
437 | CompletionItem { | ||
438 | label: "foo(…)", | ||
439 | source_range: 68..70, | ||
440 | delete: 68..70, | ||
441 | insert: "foo(${1:a}, ${2:b}, ${3:t})$0", | ||
442 | kind: SymbolKind( | ||
443 | Function, | ||
444 | ), | ||
445 | lookup: "foo", | ||
446 | detail: "fn(u32, u32, T) -> (u32, T)", | ||
447 | trigger_call_info: true, | ||
448 | }, | ||
449 | CompletionItem { | ||
450 | label: "main()", | ||
451 | source_range: 68..70, | ||
452 | delete: 68..70, | ||
453 | insert: "main()$0", | ||
454 | kind: SymbolKind( | ||
455 | Function, | ||
456 | ), | ||
457 | lookup: "main", | ||
458 | detail: "fn()", | ||
459 | }, | ||
460 | ] | ||
461 | "#]], | ||
462 | ); | ||
463 | } | ||
464 | |||
465 | #[test] | ||
428 | fn enum_detail_just_parentheses_for_unit() { | 466 | fn enum_detail_just_parentheses_for_unit() { |
429 | check( | 467 | check( |
430 | r#" | 468 | r#" |
@@ -501,7 +539,7 @@ fn main() { let _: m::Spam = S$0 } | |||
501 | Function, | 539 | Function, |
502 | ), | 540 | ), |
503 | lookup: "main", | 541 | lookup: "main", |
504 | detail: "-> ()", | 542 | detail: "fn()", |
505 | }, | 543 | }, |
506 | ] | 544 | ] |
507 | "#]], | 545 | "#]], |
@@ -530,7 +568,7 @@ fn main() { som$0 } | |||
530 | Function, | 568 | Function, |
531 | ), | 569 | ), |
532 | lookup: "main", | 570 | lookup: "main", |
533 | detail: "-> ()", | 571 | detail: "fn()", |
534 | }, | 572 | }, |
535 | CompletionItem { | 573 | CompletionItem { |
536 | label: "something_deprecated()", | 574 | label: "something_deprecated()", |
@@ -541,7 +579,7 @@ fn main() { som$0 } | |||
541 | Function, | 579 | Function, |
542 | ), | 580 | ), |
543 | lookup: "something_deprecated", | 581 | lookup: "something_deprecated", |
544 | detail: "-> ()", | 582 | detail: "fn()", |
545 | deprecated: true, | 583 | deprecated: true, |
546 | }, | 584 | }, |
547 | CompletionItem { | 585 | CompletionItem { |
@@ -553,7 +591,7 @@ fn main() { som$0 } | |||
553 | Function, | 591 | Function, |
554 | ), | 592 | ), |
555 | lookup: "something_else_deprecated", | 593 | lookup: "something_else_deprecated", |
556 | detail: "-> ()", | 594 | detail: "fn()", |
557 | deprecated: true, | 595 | deprecated: true, |
558 | }, | 596 | }, |
559 | ] | 597 | ] |
@@ -604,7 +642,7 @@ impl S { | |||
604 | insert: "bar()$0", | 642 | insert: "bar()$0", |
605 | kind: Method, | 643 | kind: Method, |
606 | lookup: "bar", | 644 | lookup: "bar", |
607 | detail: "-> ()", | 645 | detail: "fn(self)", |
608 | documentation: Documentation( | 646 | documentation: Documentation( |
609 | "Method docs", | 647 | "Method docs", |
610 | ), | 648 | ), |
@@ -704,7 +742,7 @@ fn foo(s: S) { s.$0 } | |||
704 | insert: "the_method()$0", | 742 | insert: "the_method()$0", |
705 | kind: Method, | 743 | kind: Method, |
706 | lookup: "the_method", | 744 | lookup: "the_method", |
707 | detail: "-> ()", | 745 | detail: "fn(&self)", |
708 | }, | 746 | }, |
709 | ] | 747 | ] |
710 | "#]], | 748 | "#]], |
@@ -954,7 +992,7 @@ fn main() { | |||
954 | Function, | 992 | Function, |
955 | ), | 993 | ), |
956 | lookup: "foo", | 994 | lookup: "foo", |
957 | detail: "-> ()", | 995 | detail: "fn(&mut S)", |
958 | trigger_call_info: true, | 996 | trigger_call_info: true, |
959 | }, | 997 | }, |
960 | CompletionItem { | 998 | CompletionItem { |
@@ -966,7 +1004,7 @@ fn main() { | |||
966 | Function, | 1004 | Function, |
967 | ), | 1005 | ), |
968 | lookup: "main", | 1006 | lookup: "main", |
969 | detail: "-> ()", | 1007 | detail: "fn()", |
970 | }, | 1008 | }, |
971 | CompletionItem { | 1009 | CompletionItem { |
972 | label: "s", | 1010 | label: "s", |
diff --git a/crates/ide_completion/src/render/function.rs b/crates/ide_completion/src/render/function.rs index f4dabe3d1..e154d6302 100644 --- a/crates/ide_completion/src/render/function.rs +++ b/crates/ide_completion/src/render/function.rs | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | use hir::{HasSource, HirDisplay, Type}; | 3 | use hir::{HasSource, HirDisplay, Type}; |
4 | use ide_db::SymbolKind; | 4 | use ide_db::SymbolKind; |
5 | use itertools::Itertools; | ||
5 | use syntax::ast::Fn; | 6 | use syntax::ast::Fn; |
6 | 7 | ||
7 | use crate::{ | 8 | use crate::{ |
@@ -59,8 +60,34 @@ impl<'a> FunctionRender<'a> { | |||
59 | } | 60 | } |
60 | 61 | ||
61 | fn detail(&self) -> String { | 62 | fn detail(&self) -> String { |
62 | let ty = self.func.ret_type(self.ctx.db()); | 63 | let params = if let Some(self_param) = self.func.self_param(self.ctx.db()) { |
63 | format!("-> {}", ty.display(self.ctx.db())) | 64 | let params = self |
65 | .func | ||
66 | .assoc_fn_params(self.ctx.db()) | ||
67 | .into_iter() | ||
68 | .skip(1) // skip the self param because we are manually handling that | ||
69 | .map(|p| p.ty().display(self.ctx.db()).to_string()); | ||
70 | |||
71 | std::iter::once(self_param.display(self.ctx.db()).to_owned()).chain(params).join(", ") | ||
72 | } else { | ||
73 | let params = self | ||
74 | .func | ||
75 | .assoc_fn_params(self.ctx.db()) | ||
76 | .into_iter() | ||
77 | .map(|p| p.ty().display(self.ctx.db()).to_string()) | ||
78 | .join(", "); | ||
79 | params | ||
80 | }; | ||
81 | |||
82 | let ret_ty = self.func.ret_type(self.ctx.db()); | ||
83 | let ret = if ret_ty.is_unit() { | ||
84 | // Omit the `-> ()` for unit return types | ||
85 | String::new() | ||
86 | } else { | ||
87 | format!(" -> {}", ret_ty.display(self.ctx.db())) | ||
88 | }; | ||
89 | |||
90 | format!("fn({}){}", params, ret) | ||
64 | } | 91 | } |
65 | 92 | ||
66 | fn add_arg(&self, arg: &str, ty: &Type) -> String { | 93 | fn add_arg(&self, arg: &str, ty: &Type) -> String { |