diff options
| author | Aleksey Kladov <aleksey.kladov@gmail.com> | 2020-07-04 19:03:58 +0200 |
|---|---|---|
| committer | Aleksey Kladov <aleksey.kladov@gmail.com> | 2020-07-04 19:03:58 +0200 |
| commit | 943fa4639569cc2c93d3ff8f7f5b1a30cc332cb0 (patch) | |
| tree | 90b2c90cbd9a429f18f576c52b6e7c2e0d75e5a9 | |
| parent | c14a3b4a20583acae6f636005998d64dd6bdec75 (diff) | |
| download | rust-943fa4639569cc2c93d3ff8f7f5b1a30cc332cb0.tar.gz rust-943fa4639569cc2c93d3ff8f7f5b1a30cc332cb0.zip | |
Alight details in comkplation list
| -rw-r--r-- | crates/ra_ide/src/completion/complete_dot.rs | 8 | ||||
| -rw-r--r-- | crates/ra_ide/src/completion/complete_keyword.rs | 12 | ||||
| -rw-r--r-- | crates/ra_ide/src/completion/complete_pattern.rs | 2 | ||||
| -rw-r--r-- | crates/ra_ide/src/completion/complete_postfix.rs | 24 | ||||
| -rw-r--r-- | crates/ra_ide/src/completion/complete_qualified_path.rs | 44 | ||||
| -rw-r--r-- | crates/ra_ide/src/completion/complete_snippet.rs | 6 | ||||
| -rw-r--r-- | crates/ra_ide/src/completion/test_utils.rs | 17 |
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 667a8b94993..3c6c8c81a7d 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.<|> } "#, expect![[r#" me bar() fn bar(&self) - fd foo u32 + fd foo u32 "#]], ); } @@ -98,7 +98,7 @@ impl S { } "#, expect![[r#" - me foo() fn foo(self) + me foo() fn foo(self) fd the_field (u32,) "#]], ) @@ -114,7 +114,7 @@ impl A { } "#, expect![[r#" - me foo() fn foo(&self) + me foo() fn foo(&self) fd the_field (u32, i32) "#]], ) @@ -148,7 +148,7 @@ fn foo(a: inner::A) { a.<|> } "#, expect![[r#" fd crate_field u32 - fd pub_field u32 + fd pub_field u32 fd super_field u32 "#]], ); diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs index 340d57a49c6..2dc401f575d 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 { check( r"use a::<|>", expect![[r#" - kw self - kw super:: - "#]], + kw self + kw super:: + "#]], ); check( r"use a::{b, <|>}", expect![[r#" - kw self - kw super:: - "#]], + kw self + kw super:: + "#]], ); } diff --git a/crates/ra_ide/src/completion/complete_pattern.rs b/crates/ra_ide/src/completion/complete_pattern.rs index 41c16df7b1f..13fa7548d89 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() { expect![[r#" st Bar en E - ev X () + ev X () ct Z md m "#]], diff --git a/crates/ra_ide/src/completion/complete_postfix.rs b/crates/ra_ide/src/completion/complete_postfix.rs index 14013dc2f97..8735b901037 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() { } "#, expect![[r#" - sn box Box::new(expr) - sn call function(expr) - sn dbg dbg!(expr) - sn if if expr {} + sn box Box::new(expr) + sn call function(expr) + sn dbg dbg!(expr) + sn if if expr {} sn match match expr {} - sn not !expr - sn ref &expr - sn refm &mut expr + sn not !expr + sn ref &expr + sn refm &mut expr sn while while expr {} "#]], ); @@ -283,12 +283,12 @@ fn main() { } "#, expect![[r#" - sn box Box::new(expr) - sn call function(expr) - sn dbg dbg!(expr) + sn box Box::new(expr) + sn call function(expr) + sn dbg dbg!(expr) sn match match expr {} - sn ref &expr - sn refm &mut expr + sn ref &expr + sn refm &mut expr "#]], ) } diff --git a/crates/ra_ide/src/completion/complete_qualified_path.rs b/crates/ra_ide/src/completion/complete_qualified_path.rs index ba412110368..e5553e28f57 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::<|> } "#, expect![[r#" ev Bar(…) (i32) - ev Foo () + ev Foo () "#]], ); } @@ -354,8 +354,8 @@ impl S { fn foo() { let _ = S::<|> } "#, expect![[r#" - ct C const C: i32 = 42; - ta T type T = i32; + ct C const C: i32 = 42; + ta T type T = i32; fn a() fn a() me b() fn b(&self) "#]], @@ -382,8 +382,8 @@ mod m { fn foo() { let _ = S::<|> } "#, expect![[r#" - ct PUBLIC_CONST pub(super) const PUBLIC_CONST: u32 = 1; - ta PublicType pub(super) type PublicType = u32; + ct PUBLIC_CONST pub(super) const PUBLIC_CONST: u32 = 1; + ta PublicType pub(super) type PublicType = u32; fn public_method() pub(super) fn public_method() "#]], ); @@ -504,13 +504,13 @@ trait Sub: Super { fn foo<T: Sub>() { T::<|> } "#, expect![[r#" - ct C2 const C2: (); - ct CONST const CONST: u8; - ta SubTy type SubTy; - ta Ty type Ty; - fn func() fn func() - me method() fn method(&self) - fn subfunc() fn subfunc() + ct C2 const C2: (); + ct CONST const CONST: u8; + ta SubTy type SubTy; + ta Ty type Ty; + fn func() fn func() + me method() fn method(&self) + fn subfunc() fn subfunc() me submethod() fn submethod(&self) "#]], ); @@ -544,13 +544,13 @@ impl<T> Sub for Wrap<T> { } "#, expect![[r#" - ct C2 const C2: () = (); - ct CONST const CONST: u8 = 0; - ta SubTy type SubTy; - ta Ty type Ty; - fn func() fn func() - me method() fn method(&self) - fn subfunc() fn subfunc() + ct C2 const C2: () = (); + ct CONST const CONST: u8 = 0; + ta SubTy type SubTy; + ta Ty type Ty; + fn func() fn func() + me method() fn method(&self) + fn subfunc() fn subfunc() me submethod() fn submethod(&self) "#]], ); @@ -586,7 +586,7 @@ fn main() { let _ = crate::<|> } expect![[r##" ma foo!(…) #[macro_export] macro_rules! foo - fn main() fn main() + fn main() fn main() "##]], ); } @@ -630,7 +630,7 @@ mod p { expect![[r#" ct RIGHT_CONST st RightType - fn right_fn() fn wrong_fn() + fn right_fn() fn wrong_fn() "#]], ); @@ -676,7 +676,7 @@ fn main() { m!(self::f<|>); } fn foo() {} "#, expect![[r#" - fn foo() fn foo() + fn foo() fn foo() fn main() fn main() "#]], ); diff --git a/crates/ra_ide/src/completion/complete_snippet.rs b/crates/ra_ide/src/completion/complete_snippet.rs index c700235645e..28d8f787681 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 { check( r#"fn foo(x: i32) { <|> }"#, expect![[r#" - sn pd - sn ppd - "#]], + sn pd + sn ppd + "#]], ); } diff --git a/crates/ra_ide/src/completion/test_utils.rs b/crates/ra_ide/src/completion/test_utils.rs index cbae1da859a..c2be2369783 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( .filter(|c| c.completion_kind == kind) .collect(); kind_completions.sort_by_key(|c| c.label().to_owned()); + let label_width = kind_completions + .iter() + .map(|it| monospace_width(it.label())) + .max() + .unwrap_or_default() + .min(16); kind_completions .into_iter() .map(|it| { - let mut buf = format!("{} {}", it.kind().unwrap().tag(), it.label()); + let tag = it.kind().unwrap().tag(); + let var_name = format!("{} {}", tag, it.label()); + let mut buf = var_name; if let Some(detail) = it.detail() { - format_to!(buf, " {}", detail); + let width = label_width.saturating_sub(monospace_width(it.label())); + format_to!(buf, "{:width$} {}", "", detail, width = width); } format_to!(buf, "\n"); buf @@ -56,6 +65,10 @@ pub(crate) fn completion_list_with_config( .collect() } +fn monospace_width(s: &str) -> usize { + s.chars().count() +} + pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) { check_edit_with_config(what, ra_fixture_before, ra_fixture_after, &CompletionConfig::default()) } |
