mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
limit struct field hover display nums
This commit is contained in:
parent
d81148a009
commit
1c85234bcd
4 changed files with 28 additions and 12 deletions
|
@ -185,21 +185,32 @@ impl HirDisplay for Struct {
|
||||||
write_where_clause(def_id, f)?;
|
write_where_clause(def_id, f)?;
|
||||||
}
|
}
|
||||||
StructKind::Record => {
|
StructKind::Record => {
|
||||||
|
if let Some(limit) = f.entity_limit {
|
||||||
let has_where_clause = write_where_clause(def_id, f)?;
|
let has_where_clause = write_where_clause(def_id, f)?;
|
||||||
let fields = self.fields(f.db);
|
let fields = self.fields(f.db);
|
||||||
|
let count = fields.len().min(limit);
|
||||||
f.write_char(if !has_where_clause { ' ' } else { '\n' })?;
|
f.write_char(if !has_where_clause { ' ' } else { '\n' })?;
|
||||||
|
if count == 0 {
|
||||||
if fields.is_empty() {
|
if fields.is_empty() {
|
||||||
f.write_str("{}")?;
|
f.write_str("{}")?;
|
||||||
} else {
|
} else {
|
||||||
f.write_str("{\n")?;
|
f.write_str("{ /* … */ }")?;
|
||||||
for field in self.fields(f.db) {
|
}
|
||||||
|
} else {
|
||||||
|
f.write_str(" {\n")?;
|
||||||
|
for field in &fields[..count] {
|
||||||
f.write_str(" ")?;
|
f.write_str(" ")?;
|
||||||
field.hir_fmt(f)?;
|
field.hir_fmt(f)?;
|
||||||
f.write_str(",\n")?;
|
f.write_str(",\n")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if fields.len() > count {
|
||||||
|
f.write_str(" /* … */\n")?;
|
||||||
|
}
|
||||||
f.write_str("}")?;
|
f.write_str("}")?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
StructKind::Unit => _ = write_where_clause(def_id, f)?,
|
StructKind::Unit => _ = write_where_clause(def_id, f)?,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ pub struct HoverConfig {
|
||||||
pub keywords: bool,
|
pub keywords: bool,
|
||||||
pub format: HoverDocFormat,
|
pub format: HoverDocFormat,
|
||||||
pub max_trait_assoc_items_count: Option<usize>,
|
pub max_trait_assoc_items_count: Option<usize>,
|
||||||
|
pub max_struct_field_count: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
|
|
|
@ -410,6 +410,9 @@ pub(super) fn definition(
|
||||||
Definition::Trait(trait_) => {
|
Definition::Trait(trait_) => {
|
||||||
trait_.display_limited(db, config.max_trait_assoc_items_count).to_string()
|
trait_.display_limited(db, config.max_trait_assoc_items_count).to_string()
|
||||||
}
|
}
|
||||||
|
Definition::Adt(Adt::Struct(struct_)) => {
|
||||||
|
struct_.display_limited(db, config.max_struct_field_count).to_string()
|
||||||
|
}
|
||||||
_ => def.label(db),
|
_ => def.label(db),
|
||||||
};
|
};
|
||||||
let docs = def.docs(db, famous_defs);
|
let docs = def.docs(db, famous_defs);
|
||||||
|
|
|
@ -167,6 +167,7 @@ impl StaticIndex<'_> {
|
||||||
keywords: true,
|
keywords: true,
|
||||||
format: crate::HoverDocFormat::Markdown,
|
format: crate::HoverDocFormat::Markdown,
|
||||||
max_trait_assoc_items_count: None,
|
max_trait_assoc_items_count: None,
|
||||||
|
max_struct_field_count: None,
|
||||||
};
|
};
|
||||||
let tokens = tokens.filter(|token| {
|
let tokens = tokens.filter(|token| {
|
||||||
matches!(
|
matches!(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue