mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
internal: Adjust a few things for trait assoc item hovers
This commit is contained in:
parent
ce3216e0ae
commit
b20e467373
7 changed files with 397 additions and 324 deletions
|
@ -596,33 +596,32 @@ impl HirDisplay for Trait {
|
|||
write_generic_params(def_id, f)?;
|
||||
write_where_clause(def_id, f)?;
|
||||
|
||||
let assoc_items = self.items(f.db);
|
||||
let assoc_items_size = assoc_items.len();
|
||||
let limited_size = f.limited_size.unwrap_or(assoc_items_size);
|
||||
if assoc_items.is_empty() {
|
||||
f.write_str(" {}")?;
|
||||
} else {
|
||||
f.write_str(" {\n")?;
|
||||
for (index, item) in assoc_items.iter().enumerate() {
|
||||
f.write_str(" ")?;
|
||||
match item {
|
||||
AssocItem::Function(func) => {
|
||||
func.hir_fmt(f)?;
|
||||
}
|
||||
AssocItem::Const(cst) => {
|
||||
cst.hir_fmt(f)?;
|
||||
}
|
||||
AssocItem::TypeAlias(type_alias) => {
|
||||
type_alias.hir_fmt(f)?;
|
||||
}
|
||||
};
|
||||
f.write_str(",\n")?;
|
||||
if index + 1 == limited_size && index + 1 != assoc_items_size {
|
||||
f.write_str(" ...\n")?;
|
||||
break;
|
||||
if let Some(limit) = f.entity_limit {
|
||||
let assoc_items = self.items(f.db);
|
||||
let count = assoc_items.len().min(limit);
|
||||
if count == 0 {
|
||||
if assoc_items.is_empty() {
|
||||
f.write_str(" {}")?;
|
||||
} else {
|
||||
f.write_str(" { /* … */ }")?;
|
||||
}
|
||||
} else {
|
||||
f.write_str(" {\n")?;
|
||||
for item in &assoc_items[..count] {
|
||||
f.write_str(" ")?;
|
||||
match item {
|
||||
AssocItem::Function(func) => func.hir_fmt(f),
|
||||
AssocItem::Const(cst) => cst.hir_fmt(f),
|
||||
AssocItem::TypeAlias(type_alias) => type_alias.hir_fmt(f),
|
||||
}?;
|
||||
f.write_str(";\n")?;
|
||||
}
|
||||
|
||||
if assoc_items.len() > count {
|
||||
f.write_str(" /* … */\n")?;
|
||||
}
|
||||
f.write_str("}")?;
|
||||
}
|
||||
f.write_str("}")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue