aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion/test_utils.rs
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/test_utils.rs
parentc14a3b4a20583acae6f636005998d64dd6bdec75 (diff)
Alight details in comkplation list
Diffstat (limited to 'crates/ra_ide/src/completion/test_utils.rs')
-rw-r--r--crates/ra_ide/src/completion/test_utils.rs17
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
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}