aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-07-04 18:03:58 +0100
committerAleksey Kladov <[email protected]>2020-07-04 18:03:58 +0100
commit943fa4639569cc2c93d3ff8f7f5b1a30cc332cb0 (patch)
tree90b2c90cbd9a429f18f576c52b6e7c2e0d75e5a9 /crates/ra_ide/src/completion
parentc14a3b4a20583acae6f636005998d64dd6bdec75 (diff)
Alight details in comkplation list
Diffstat (limited to 'crates/ra_ide/src/completion')
-rw-r--r--crates/ra_ide/src/completion/complete_dot.rs8
-rw-r--r--crates/ra_ide/src/completion/complete_keyword.rs12
-rw-r--r--crates/ra_ide/src/completion/complete_pattern.rs2
-rw-r--r--crates/ra_ide/src/completion/complete_postfix.rs24
-rw-r--r--crates/ra_ide/src/completion/complete_qualified_path.rs44
-rw-r--r--crates/ra_ide/src/completion/complete_snippet.rs6
-rw-r--r--crates/ra_ide/src/completion/test_utils.rs17
7 files changed, 63 insertions, 50 deletions
diff --git a/crates/ra_ide/src/completion/complete_dot.rs b/crates/ra_ide/src/completion/complete_dot.rs
index 667a8b949..3c6c8c81a 100644
--- a/crates/ra_ide/src/completion/complete_dot.rs
+++ b/crates/ra_ide/src/completion/complete_dot.rs
@@ -83,7 +83,7 @@ fn foo(s: S) { s.<|> }
83"#, 83"#,
84 expect![[r#" 84 expect![[r#"
85 me bar() fn bar(&self) 85 me bar() fn bar(&self)
86 fd foo u32 86 fd foo u32
87 "#]], 87 "#]],
88 ); 88 );
89 } 89 }
@@ -98,7 +98,7 @@ impl S {
98} 98}
99"#, 99"#,
100 expect![[r#" 100 expect![[r#"
101 me foo() fn foo(self) 101 me foo() fn foo(self)
102 fd the_field (u32,) 102 fd the_field (u32,)
103 "#]], 103 "#]],
104 ) 104 )
@@ -114,7 +114,7 @@ impl A {
114} 114}
115"#, 115"#,
116 expect![[r#" 116 expect![[r#"
117 me foo() fn foo(&self) 117 me foo() fn foo(&self)
118 fd the_field (u32, i32) 118 fd the_field (u32, i32)
119 "#]], 119 "#]],
120 ) 120 )
@@ -148,7 +148,7 @@ fn foo(a: inner::A) { a.<|> }
148"#, 148"#,
149 expect![[r#" 149 expect![[r#"
150 fd crate_field u32 150 fd crate_field u32
151 fd pub_field u32 151 fd pub_field u32
152 fd super_field u32 152 fd super_field u32
153 "#]], 153 "#]],
154 ); 154 );
diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs
index 340d57a49..2dc401f57 100644
--- a/crates/ra_ide/src/completion/complete_keyword.rs
+++ b/crates/ra_ide/src/completion/complete_keyword.rs
@@ -216,17 +216,17 @@ mod tests {
216 check( 216 check(
217 r"use a::<|>", 217 r"use a::<|>",
218 expect![[r#" 218 expect![[r#"
219 kw self 219 kw self
220 kw super:: 220 kw super::
221 "#]], 221 "#]],
222 ); 222 );
223 223
224 check( 224 check(
225 r"use a::{b, <|>}", 225 r"use a::{b, <|>}",
226 expect![[r#" 226 expect![[r#"
227 kw self 227 kw self
228 kw super:: 228 kw super::
229 "#]], 229 "#]],
230 ); 230 );
231 } 231 }
232 232
diff --git a/crates/ra_ide/src/completion/complete_pattern.rs b/crates/ra_ide/src/completion/complete_pattern.rs
index 41c16df7b..13fa7548d 100644
--- a/crates/ra_ide/src/completion/complete_pattern.rs
+++ b/crates/ra_ide/src/completion/complete_pattern.rs
@@ -61,7 +61,7 @@ fn foo() {
61 expect![[r#" 61 expect![[r#"
62 st Bar 62 st Bar
63 en E 63 en E
64 ev X () 64 ev X ()
65 ct Z 65 ct Z
66 md m 66 md m
67 "#]], 67 "#]],
diff --git a/crates/ra_ide/src/completion/complete_postfix.rs b/crates/ra_ide/src/completion/complete_postfix.rs
index 14013dc2f..8735b9010 100644
--- a/crates/ra_ide/src/completion/complete_postfix.rs
+++ b/crates/ra_ide/src/completion/complete_postfix.rs
@@ -260,14 +260,14 @@ fn main() {
260} 260}
261"#, 261"#,
262 expect![[r#" 262 expect![[r#"
263 sn box Box::new(expr) 263 sn box Box::new(expr)
264 sn call function(expr) 264 sn call function(expr)
265 sn dbg dbg!(expr) 265 sn dbg dbg!(expr)
266 sn if if expr {} 266 sn if if expr {}
267 sn match match expr {} 267 sn match match expr {}
268 sn not !expr 268 sn not !expr
269 sn ref &expr 269 sn ref &expr
270 sn refm &mut expr 270 sn refm &mut expr
271 sn while while expr {} 271 sn while while expr {}
272 "#]], 272 "#]],
273 ); 273 );
@@ -283,12 +283,12 @@ fn main() {
283} 283}
284"#, 284"#,
285 expect![[r#" 285 expect![[r#"
286 sn box Box::new(expr) 286 sn box Box::new(expr)
287 sn call function(expr) 287 sn call function(expr)
288 sn dbg dbg!(expr) 288 sn dbg dbg!(expr)
289 sn match match expr {} 289 sn match match expr {}
290 sn ref &expr 290 sn ref &expr
291 sn refm &mut expr 291 sn refm &mut expr
292 "#]], 292 "#]],
293 ) 293 )
294 } 294 }
diff --git a/crates/ra_ide/src/completion/complete_qualified_path.rs b/crates/ra_ide/src/completion/complete_qualified_path.rs
index ba4121103..e5553e28f 100644
--- a/crates/ra_ide/src/completion/complete_qualified_path.rs
+++ b/crates/ra_ide/src/completion/complete_qualified_path.rs
@@ -332,7 +332,7 @@ fn foo() { let _ = E::<|> }
332"#, 332"#,
333 expect![[r#" 333 expect![[r#"
334 ev Bar(…) (i32) 334 ev Bar(…) (i32)
335 ev Foo () 335 ev Foo ()
336 "#]], 336 "#]],
337 ); 337 );
338 } 338 }
@@ -354,8 +354,8 @@ impl S {
354fn foo() { let _ = S::<|> } 354fn foo() { let _ = S::<|> }
355"#, 355"#,
356 expect![[r#" 356 expect![[r#"
357 ct C const C: i32 = 42; 357 ct C const C: i32 = 42;
358 ta T type T = i32; 358 ta T type T = i32;
359 fn a() fn a() 359 fn a() fn a()
360 me b() fn b(&self) 360 me b() fn b(&self)
361 "#]], 361 "#]],
@@ -382,8 +382,8 @@ mod m {
382fn foo() { let _ = S::<|> } 382fn foo() { let _ = S::<|> }
383"#, 383"#,
384 expect![[r#" 384 expect![[r#"
385 ct PUBLIC_CONST pub(super) const PUBLIC_CONST: u32 = 1; 385 ct PUBLIC_CONST pub(super) const PUBLIC_CONST: u32 = 1;
386 ta PublicType pub(super) type PublicType = u32; 386 ta PublicType pub(super) type PublicType = u32;
387 fn public_method() pub(super) fn public_method() 387 fn public_method() pub(super) fn public_method()
388 "#]], 388 "#]],
389 ); 389 );
@@ -504,13 +504,13 @@ trait Sub: Super {
504fn foo<T: Sub>() { T::<|> } 504fn foo<T: Sub>() { T::<|> }
505"#, 505"#,
506 expect![[r#" 506 expect![[r#"
507 ct C2 const C2: (); 507 ct C2 const C2: ();
508 ct CONST const CONST: u8; 508 ct CONST const CONST: u8;
509 ta SubTy type SubTy; 509 ta SubTy type SubTy;
510 ta Ty type Ty; 510 ta Ty type Ty;
511 fn func() fn func() 511 fn func() fn func()
512 me method() fn method(&self) 512 me method() fn method(&self)
513 fn subfunc() fn subfunc() 513 fn subfunc() fn subfunc()
514 me submethod() fn submethod(&self) 514 me submethod() fn submethod(&self)
515 "#]], 515 "#]],
516 ); 516 );
@@ -544,13 +544,13 @@ impl<T> Sub for Wrap<T> {
544} 544}
545"#, 545"#,
546 expect![[r#" 546 expect![[r#"
547 ct C2 const C2: () = (); 547 ct C2 const C2: () = ();
548 ct CONST const CONST: u8 = 0; 548 ct CONST const CONST: u8 = 0;
549 ta SubTy type SubTy; 549 ta SubTy type SubTy;
550 ta Ty type Ty; 550 ta Ty type Ty;
551 fn func() fn func() 551 fn func() fn func()
552 me method() fn method(&self) 552 me method() fn method(&self)
553 fn subfunc() fn subfunc() 553 fn subfunc() fn subfunc()
554 me submethod() fn submethod(&self) 554 me submethod() fn submethod(&self)
555 "#]], 555 "#]],
556 ); 556 );
@@ -586,7 +586,7 @@ fn main() { let _ = crate::<|> }
586 expect![[r##" 586 expect![[r##"
587 ma foo!(…) #[macro_export] 587 ma foo!(…) #[macro_export]
588 macro_rules! foo 588 macro_rules! foo
589 fn main() fn main() 589 fn main() fn main()
590 "##]], 590 "##]],
591 ); 591 );
592 } 592 }
@@ -630,7 +630,7 @@ mod p {
630 expect![[r#" 630 expect![[r#"
631 ct RIGHT_CONST 631 ct RIGHT_CONST
632 st RightType 632 st RightType
633 fn right_fn() fn wrong_fn() 633 fn right_fn() fn wrong_fn()
634 "#]], 634 "#]],
635 ); 635 );
636 636
@@ -676,7 +676,7 @@ fn main() { m!(self::f<|>); }
676fn foo() {} 676fn foo() {}
677"#, 677"#,
678 expect![[r#" 678 expect![[r#"
679 fn foo() fn foo() 679 fn foo() fn foo()
680 fn main() fn main() 680 fn main() fn main()
681 "#]], 681 "#]],
682 ); 682 );
diff --git a/crates/ra_ide/src/completion/complete_snippet.rs b/crates/ra_ide/src/completion/complete_snippet.rs
index c70023564..28d8f7876 100644
--- a/crates/ra_ide/src/completion/complete_snippet.rs
+++ b/crates/ra_ide/src/completion/complete_snippet.rs
@@ -84,9 +84,9 @@ mod tests {
84 check( 84 check(
85 r#"fn foo(x: i32) { <|> }"#, 85 r#"fn foo(x: i32) { <|> }"#,
86 expect![[r#" 86 expect![[r#"
87 sn pd 87 sn pd
88 sn ppd 88 sn ppd
89 "#]], 89 "#]],
90 ); 90 );
91 } 91 }
92 92
diff --git a/crates/ra_ide/src/completion/test_utils.rs b/crates/ra_ide/src/completion/test_utils.rs
index cbae1da85..c2be23697 100644
--- a/crates/ra_ide/src/completion/test_utils.rs
+++ b/crates/ra_ide/src/completion/test_utils.rs
@@ -43,12 +43,21 @@ pub(crate) fn completion_list_with_config(
43 .filter(|c| c.completion_kind == kind) 43 .filter(|c| c.completion_kind == kind)
44 .collect(); 44 .collect();
45 kind_completions.sort_by_key(|c| c.label().to_owned()); 45 kind_completions.sort_by_key(|c| c.label().to_owned());
46 let label_width = kind_completions
47 .iter()
48 .map(|it| monospace_width(it.label()))
49 .max()
50 .unwrap_or_default()
51 .min(16);
46 kind_completions 52 kind_completions
47 .into_iter() 53 .into_iter()
48 .map(|it| { 54 .map(|it| {
49 let mut buf = format!("{} {}", it.kind().unwrap().tag(), it.label()); 55 let tag = it.kind().unwrap().tag();
56 let var_name = format!("{} {}", tag, it.label());
57 let mut buf = var_name;
50 if let Some(detail) = it.detail() { 58 if let Some(detail) = it.detail() {
51 format_to!(buf, " {}", detail); 59 let width = label_width.saturating_sub(monospace_width(it.label()));
60 format_to!(buf, "{:width$} {}", "", detail, width = width);
52 } 61 }
53 format_to!(buf, "\n"); 62 format_to!(buf, "\n");
54 buf 63 buf
@@ -56,6 +65,10 @@ pub(crate) fn completion_list_with_config(
56 .collect() 65 .collect()
57} 66}
58 67
68fn monospace_width(s: &str) -> usize {
69 s.chars().count()
70}
71
59pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) { 72pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
60 check_edit_with_config(what, ra_fixture_before, ra_fixture_after, &CompletionConfig::default()) 73 check_edit_with_config(what, ra_fixture_before, ra_fixture_after, &CompletionConfig::default())
61} 74}