Update tests

This commit is contained in:
Andrew Hlynskyi 2023-11-24 13:28:30 +02:00
parent 615abb3c92
commit f0adf8c4ec
2 changed files with 21 additions and 4 deletions

View file

@ -150,16 +150,29 @@ fn render_completion_list(completions: Vec<CompletionItem>) -> String {
fn monospace_width(s: &str) -> usize {
s.chars().count()
}
let label_width =
completions.iter().map(|it| monospace_width(&it.label)).max().unwrap_or_default().min(22);
let label_width = completions
.iter()
.map(|it| {
monospace_width(&it.label)
+ monospace_width(it.label_detail.as_deref().unwrap_or_default())
})
.max()
.unwrap_or_default()
.min(22);
completions
.into_iter()
.map(|it| {
let tag = it.kind.tag();
let var_name = format!("{tag} {}", it.label);
let mut buf = var_name;
if let Some(ref label_detail) = it.label_detail {
format_to!(buf, "{label_detail}");
}
if let Some(detail) = it.detail {
let width = label_width.saturating_sub(monospace_width(&it.label));
let width = label_width.saturating_sub(
monospace_width(&it.label)
+ monospace_width(&it.label_detail.unwrap_or_default()),
);
format_to!(buf, "{:width$} {}", "", detail, width = width);
}
if it.deprecated {