aboutsummaryrefslogtreecommitdiff
path: root/crates/completion/src/render.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/completion/src/render.rs')
-rw-r--r--crates/completion/src/render.rs61
1 files changed, 30 insertions, 31 deletions
diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs
index 1ba7201a1..e93c59f71 100644
--- a/crates/completion/src/render.rs
+++ b/crates/completion/src/render.rs
@@ -11,13 +11,13 @@ pub(crate) mod type_alias;
11mod builder_ext; 11mod builder_ext;
12 12
13use hir::{Documentation, HasAttrs, HirDisplay, Mutability, ScopeDef, Type}; 13use hir::{Documentation, HasAttrs, HirDisplay, Mutability, ScopeDef, Type};
14use ide_db::RootDatabase; 14use ide_db::{helpers::SnippetCap, RootDatabase};
15use syntax::TextRange; 15use syntax::TextRange;
16use test_utils::mark; 16use test_utils::mark;
17 17
18use crate::{ 18use crate::{
19 config::SnippetCap, item::ImportEdit, CompletionContext, CompletionItem, CompletionItemKind, 19 item::ImportEdit, CompletionContext, CompletionItem, CompletionItemKind, CompletionKind,
20 CompletionKind, CompletionScore, 20 CompletionScore,
21}; 21};
22 22
23use crate::render::{enum_variant::render_variant, function::render_fn, macro_::render_macro}; 23use crate::render::{enum_variant::render_variant, function::render_fn, macro_::render_macro};
@@ -157,8 +157,7 @@ impl<'a> Render<'a> {
157 157
158 let kind = match resolution { 158 let kind = match resolution {
159 ScopeDef::ModuleDef(Function(func)) => { 159 ScopeDef::ModuleDef(Function(func)) => {
160 let item = render_fn(self.ctx, import_to_add, Some(local_name), *func); 160 return render_fn(self.ctx, import_to_add, Some(local_name), *func);
161 return Some(item);
162 } 161 }
163 ScopeDef::ModuleDef(Variant(_)) 162 ScopeDef::ModuleDef(Variant(_))
164 if self.ctx.completion.is_pat_binding_or_const 163 if self.ctx.completion.is_pat_binding_or_const
@@ -321,8 +320,8 @@ mod tests {
321 use test_utils::mark; 320 use test_utils::mark;
322 321
323 use crate::{ 322 use crate::{
324 test_utils::{check_edit, do_completion, get_all_items}, 323 test_utils::{check_edit, do_completion, get_all_items, TEST_CONFIG},
325 CompletionConfig, CompletionKind, CompletionScore, 324 CompletionKind, CompletionScore,
326 }; 325 };
327 326
328 fn check(ra_fixture: &str, expect: Expect) { 327 fn check(ra_fixture: &str, expect: Expect) {
@@ -339,7 +338,7 @@ mod tests {
339 } 338 }
340 } 339 }
341 340
342 let mut completions = get_all_items(CompletionConfig::default(), ra_fixture); 341 let mut completions = get_all_items(TEST_CONFIG, ra_fixture);
343 completions.sort_by_key(|it| (Reverse(it.score()), it.label().to_string())); 342 completions.sort_by_key(|it| (Reverse(it.score()), it.label().to_string()));
344 let actual = completions 343 let actual = completions
345 .into_iter() 344 .into_iter()
@@ -359,7 +358,7 @@ mod tests {
359 r#" 358 r#"
360enum Foo { Foo { x: i32, y: i32 } } 359enum Foo { Foo { x: i32, y: i32 } }
361 360
362fn main() { Foo::Fo<|> } 361fn main() { Foo::Fo$0 }
363"#, 362"#,
364 expect![[r#" 363 expect![[r#"
365 [ 364 [
@@ -382,7 +381,7 @@ fn main() { Foo::Fo<|> }
382 r#" 381 r#"
383enum Foo { Foo (i32, i32) } 382enum Foo { Foo (i32, i32) }
384 383
385fn main() { Foo::Fo<|> } 384fn main() { Foo::Fo$0 }
386"#, 385"#,
387 expect![[r#" 386 expect![[r#"
388 [ 387 [
@@ -407,7 +406,7 @@ fn main() { Foo::Fo<|> }
407 r#" 406 r#"
408enum Foo { Foo } 407enum Foo { Foo }
409 408
410fn main() { Foo::Fo<|> } 409fn main() { Foo::Fo$0 }
411"#, 410"#,
412 expect![[r#" 411 expect![[r#"
413 [ 412 [
@@ -431,7 +430,7 @@ fn main() { Foo::Fo<|> }
431mod m { 430mod m {
432 pub enum Spam { Foo, Bar(i32) } 431 pub enum Spam { Foo, Bar(i32) }
433} 432}
434fn main() { let _: m::Spam = S<|> } 433fn main() { let _: m::Spam = S$0 }
435"#, 434"#,
436 expect![[r#" 435 expect![[r#"
437 [ 436 [
@@ -484,7 +483,7 @@ fn something_deprecated() {}
484#[deprecated(since = "1.0.0")] 483#[deprecated(since = "1.0.0")]
485fn something_else_deprecated() {} 484fn something_else_deprecated() {}
486 485
487fn main() { som<|> } 486fn main() { som$0 }
488"#, 487"#,
489 expect![[r#" 488 expect![[r#"
490 [ 489 [
@@ -524,7 +523,7 @@ fn main() { som<|> }
524 check( 523 check(
525 r#" 524 r#"
526struct A { #[deprecated] the_field: u32 } 525struct A { #[deprecated] the_field: u32 }
527fn foo() { A { the<|> } } 526fn foo() { A { the$0 } }
528"#, 527"#,
529 expect![[r#" 528 expect![[r#"
530 [ 529 [
@@ -552,7 +551,7 @@ struct S {
552} 551}
553impl S { 552impl S {
554 /// Method docs 553 /// Method docs
555 fn bar(self) { self.<|> } 554 fn bar(self) { self.$0 }
556}"#, 555}"#,
557 expect![[r#" 556 expect![[r#"
558 [ 557 [
@@ -585,7 +584,7 @@ impl S {
585 584
586 check( 585 check(
587 r#" 586 r#"
588use self::my<|>; 587use self::my$0;
589 588
590/// mod docs 589/// mod docs
591mod my { } 590mod my { }
@@ -644,7 +643,7 @@ impl S {
644 #[inline] 643 #[inline]
645 fn the_method(&self) { } 644 fn the_method(&self) { }
646} 645}
647fn foo(s: S) { s.<|> } 646fn foo(s: S) { s.$0 }
648"#, 647"#,
649 expect![[r#" 648 expect![[r#"
650 [ 649 [
@@ -672,7 +671,7 @@ fn foo(foo: u8, bar: u8) {}
672struct ManualVtable { f: fn(u8, u8) } 671struct ManualVtable { f: fn(u8, u8) }
673 672
674fn main() -> ManualVtable { 673fn main() -> ManualVtable {
675 ManualVtable { f: f<|> } 674 ManualVtable { f: f$0 }
676} 675}
677"#, 676"#,
678 r#" 677 r#"
@@ -693,7 +692,7 @@ fn main() -> ManualVtable {
693 "foo", 692 "foo",
694 r#" 693 r#"
695mod m { pub fn foo() {} } 694mod m { pub fn foo() {} }
696use crate::m::f<|>; 695use crate::m::f$0;
697"#, 696"#,
698 r#" 697 r#"
699mod m { pub fn foo() {} } 698mod m { pub fn foo() {} }
@@ -708,7 +707,7 @@ use crate::m::foo;
708 "foo", 707 "foo",
709 r#" 708 r#"
710fn foo(x: i32) {} 709fn foo(x: i32) {}
711fn main() { f<|>(); } 710fn main() { f$0(); }
712"#, 711"#,
713 r#" 712 r#"
714fn foo(x: i32) {} 713fn foo(x: i32) {}
@@ -720,7 +719,7 @@ fn main() { foo(); }
720 r#" 719 r#"
721struct Foo; 720struct Foo;
722impl Foo { fn foo(&self){} } 721impl Foo { fn foo(&self){} }
723fn f(foo: &Foo) { foo.f<|>(); } 722fn f(foo: &Foo) { foo.f$0(); }
724"#, 723"#,
725 r#" 724 r#"
726struct Foo; 725struct Foo;
@@ -737,7 +736,7 @@ fn f(foo: &Foo) { foo.foo(); }
737 "Vec", 736 "Vec",
738 r#" 737 r#"
739struct Vec<T> {} 738struct Vec<T> {}
740fn foo(xs: Ve<|>) 739fn foo(xs: Ve$0)
741"#, 740"#,
742 r#" 741 r#"
743struct Vec<T> {} 742struct Vec<T> {}
@@ -748,7 +747,7 @@ fn foo(xs: Vec<$0>)
748 "Vec", 747 "Vec",
749 r#" 748 r#"
750type Vec<T> = (T,); 749type Vec<T> = (T,);
751fn foo(xs: Ve<|>) 750fn foo(xs: Ve$0)
752"#, 751"#,
753 r#" 752 r#"
754type Vec<T> = (T,); 753type Vec<T> = (T,);
@@ -759,7 +758,7 @@ fn foo(xs: Vec<$0>)
759 "Vec", 758 "Vec",
760 r#" 759 r#"
761struct Vec<T = i128> {} 760struct Vec<T = i128> {}
762fn foo(xs: Ve<|>) 761fn foo(xs: Ve$0)
763"#, 762"#,
764 r#" 763 r#"
765struct Vec<T = i128> {} 764struct Vec<T = i128> {}
@@ -770,7 +769,7 @@ fn foo(xs: Vec)
770 "Vec", 769 "Vec",
771 r#" 770 r#"
772struct Vec<T> {} 771struct Vec<T> {}
773fn foo(xs: Ve<|><i128>) 772fn foo(xs: Ve$0<i128>)
774"#, 773"#,
775 r#" 774 r#"
776struct Vec<T> {} 775struct Vec<T> {}
@@ -786,7 +785,7 @@ fn foo(xs: Vec<i128>)
786 r#" 785 r#"
787struct S { foo: i64, bar: u32, baz: u32 } 786struct S { foo: i64, bar: u32, baz: u32 }
788fn test(bar: u32) { } 787fn test(bar: u32) { }
789fn foo(s: S) { test(s.<|>) } 788fn foo(s: S) { test(s.$0) }
790"#, 789"#,
791 expect![[r#" 790 expect![[r#"
792 fd bar [type+name] 791 fd bar [type+name]
@@ -803,7 +802,7 @@ fn foo(s: S) { test(s.<|>) }
803 r#" 802 r#"
804struct A { foo: i64, bar: u32, baz: u32 } 803struct A { foo: i64, bar: u32, baz: u32 }
805struct B { x: (), y: f32, bar: u32 } 804struct B { x: (), y: f32, bar: u32 }
806fn foo(a: A) { B { bar: a.<|> }; } 805fn foo(a: A) { B { bar: a.$0 }; }
807"#, 806"#,
808 expect![[r#" 807 expect![[r#"
809 fd bar [type+name] 808 fd bar [type+name]
@@ -820,7 +819,7 @@ fn foo(a: A) { B { bar: a.<|> }; }
820struct A { foo: i64, bar: u32, baz: u32 } 819struct A { foo: i64, bar: u32, baz: u32 }
821struct B { x: (), y: f32, bar: u32 } 820struct B { x: (), y: f32, bar: u32 }
822fn f(foo: i64) { } 821fn f(foo: i64) { }
823fn foo(a: A) { B { bar: f(a.<|>) }; } 822fn foo(a: A) { B { bar: f(a.$0) }; }
824"#, 823"#,
825 expect![[r#" 824 expect![[r#"
826 fd foo [type+name] 825 fd foo [type+name]
@@ -833,7 +832,7 @@ fn foo(a: A) { B { bar: f(a.<|>) }; }
833struct A { foo: i64, bar: u32, baz: u32 } 832struct A { foo: i64, bar: u32, baz: u32 }
834struct B { x: (), y: f32, bar: u32 } 833struct B { x: (), y: f32, bar: u32 }
835fn f(foo: i64) { } 834fn f(foo: i64) { }
836fn foo(a: A) { f(B { bar: a.<|> }); } 835fn foo(a: A) { f(B { bar: a.$0 }); }
837"#, 836"#,
838 expect![[r#" 837 expect![[r#"
839 fd bar [type+name] 838 fd bar [type+name]
@@ -848,7 +847,7 @@ fn foo(a: A) { f(B { bar: a.<|> }); }
848 check_scores( 847 check_scores(
849 r#" 848 r#"
850struct WorldSnapshot { _f: () }; 849struct WorldSnapshot { _f: () };
851fn go(world: &WorldSnapshot) { go(w<|>) } 850fn go(world: &WorldSnapshot) { go(w$0) }
852"#, 851"#,
853 expect![[r#" 852 expect![[r#"
854 bn world [type+name] 853 bn world [type+name]
@@ -863,7 +862,7 @@ fn go(world: &WorldSnapshot) { go(w<|>) }
863 check_scores( 862 check_scores(
864 r#" 863 r#"
865struct Foo; 864struct Foo;
866fn f(foo: &Foo) { f(foo, w<|>) } 865fn f(foo: &Foo) { f(foo, w$0) }
867"#, 866"#,
868 expect![[r#" 867 expect![[r#"
869 st Foo [] 868 st Foo []