diff options
Diffstat (limited to 'crates/ra_ide/src/completion/test_utils.rs')
-rw-r--r-- | crates/ra_ide/src/completion/test_utils.rs | 17 |
1 files changed, 15 insertions, 2 deletions
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 | ||
68 | fn monospace_width(s: &str) -> usize { | ||
69 | s.chars().count() | ||
70 | } | ||
71 | |||
59 | pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) { | 72 | pub(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 | } |