Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: limit struct hover display nums #16906

Merged
merged 5 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
limit struct field hover display nums
  • Loading branch information
Young-Flash committed Mar 25, 2024
commit 1c85234bcdbc7c863e737e9f3329518beeb436c3
35 changes: 23 additions & 12 deletions crates/hir/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,30 @@ impl HirDisplay for Struct {
write_where_clause(def_id, f)?;
}
StructKind::Record => {
let has_where_clause = write_where_clause(def_id, f)?;
let fields = self.fields(f.db);
f.write_char(if !has_where_clause { ' ' } else { '\n' })?;
if fields.is_empty() {
f.write_str("{}")?;
} else {
f.write_str("{\n")?;
for field in self.fields(f.db) {
f.write_str(" ")?;
field.hir_fmt(f)?;
f.write_str(",\n")?;
if let Some(limit) = f.entity_limit {
let has_where_clause = write_where_clause(def_id, f)?;
let fields = self.fields(f.db);
let count = fields.len().min(limit);
f.write_char(if !has_where_clause { ' ' } else { '\n' })?;
if count == 0 {
if fields.is_empty() {
f.write_str("{}")?;
} else {
f.write_str("{ /* … */ }")?;
}
} else {
f.write_str(" {\n")?;
for field in &fields[..count] {
f.write_str(" ")?;
field.hir_fmt(f)?;
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)?,
Expand Down
1 change: 1 addition & 0 deletions crates/ide/src/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct HoverConfig {
pub keywords: bool,
pub format: HoverDocFormat,
pub max_trait_assoc_items_count: Option<usize>,
pub max_struct_field_count: Option<usize>,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down
3 changes: 3 additions & 0 deletions crates/ide/src/hover/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ pub(super) fn definition(
Definition::Trait(trait_) => {
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),
};
let docs = def.docs(db, famous_defs);
Expand Down
1 change: 1 addition & 0 deletions crates/ide/src/static_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ impl StaticIndex<'_> {
keywords: true,
format: crate::HoverDocFormat::Markdown,
max_trait_assoc_items_count: None,
max_struct_field_count: None,
};
let tokens = tokens.filter(|token| {
matches!(
Expand Down