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

Support hovering limits for adts #17021

Merged
merged 7 commits into from
Apr 25, 2024
Merged

Conversation

roife
Copy link
Member

@roife roife commented Apr 6, 2024

Fix #17009

  1. Currently, r-a supports limiting the number of struct fields displayed when hovering. This PR extends it to support enum variants and union fields. Since the display of these three (ADTs) is similar, this PR extends 'hover_show_structFields' to 'hover_show_adtFieldsOrVariants'.
  2. This PR also resolved the problem that the layout of ADT was not restricted by display limitations when hovering on the Self type.
  3. Additionally, this PR changes the default value of display limitations to 10 (instead of the original null), which helps users discover this feature.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 6, 2024
@roife roife force-pushed the add-hover-limits-for-adts branch 2 times, most recently from f405b4a to 0ec41cd Compare April 6, 2024 06:53
Copy link
Member

@Young-Flash Young-Flash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

small nit: IMO default "10" is a little big, 10 fields exceeding the hover windows

image

@roife
Copy link
Member Author

roife commented Apr 7, 2024

How about changing the default limitation to 5?

@l1nxy
Copy link
Contributor

l1nxy commented Apr 8, 2024

I'm wondering if the change in configuration should be documented on #4604.

@lnicola
Copy link
Member

lnicola commented Apr 8, 2024

I'm wondering if the change in configuration should be documented on #4604.

That's mainly for protocol changes (extensions), but we do have a compatibility mechanism for renamed settings.

@bors
Copy link
Collaborator

bors commented Apr 16, 2024

☔ The latest upstream changes (presumably #16639) made this pull request unmergeable. Please resolve the merge conflicts.

@roife roife force-pushed the add-hover-limits-for-adts branch from edac1b5 to 6bb8598 Compare April 16, 2024 08:29
f.write_str(",\n")?;
}
f.write_str("}")?;
fn display_fields_or_variants<T: HirDisplay>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should split this into two, one for fields one for variants. Reason being for an enum like

enum Enum {
    Variant {},
    Variant2 { field: Field },
    Variant3(),
    Variant4(Field),
    Variant5,
}

hovering the enum should yield

enum Enum {
    Variant {},
    Variant2 { .. }, // or the field if the limit is enabled and non-zero
    Variant3(),
    Variant4(,.), , // or the field if the limit is enabled and non-zero
    Variant5,
}

That is hovering an enum should only show its shape, not its vairants fields. To see those the person can hover the variant instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variant2 { .. }, // or the field if the limit is enabled and non-zero

Here I use a single config to limit the num of fields or variants of ADTs, should we separate it into two different ones?

Copy link
Member

@Veykril Veykril Apr 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah wait I made a mistake, hovering enums should not render the variants fields (well I said that already but my example has incorrect comments I guess).

Splitting the two into two configs sounds reasonable nevertheless.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, for hovering on enums, we can display it as 🤔

enum Enum {
    Variant {},
    Variant2 { /* .. */ },
    Variant3(),
    Variant4( /* .. */ ),
    Variant5,
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, basically for the variants we want to use the same format that is used for when we set the config to 0 for fields on structs / unions. (which fits your example here)

crates/ide/src/hover/tests.rs Outdated Show resolved Hide resolved
crates/ide/src/hover/tests.rs Outdated Show resolved Hide resolved
crates/ide/src/hover/tests.rs Show resolved Hide resolved
crates/ide/src/hover/tests.rs Show resolved Hide resolved
@Veykril Veykril added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 18, 2024
@roife roife force-pushed the add-hover-limits-for-adts branch from adbefb8 to e0e28ec Compare April 19, 2024 13:46
@roife
Copy link
Member Author

roife commented Apr 19, 2024

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 19, 2024
Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last review round

@@ -410,8 +410,20 @@ 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()
Definition::Adt(adt @ (Adt::Struct(_) | Adt::Union(_))) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do this branch for Definition::Variant as well

/// How many variants of an enum to display when hovering on. Show none if empty.
hover_show_enumVariants: Option<usize> = Some(5),
/// How many fields of a struct or union to display when hovering on. Show none if empty.
hover_show_structOrUnionFields: Option<usize> = Some(5),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hover_show_structOrUnionFields: Option<usize> = Some(5),
hover_show_fields: Option<usize> = Some(5),

since this should also work for enum variants, so just fields should be good enough

@roife roife force-pushed the add-hover-limits-for-adts branch from 99c3794 to 4357698 Compare April 20, 2024 01:14
@Veykril
Copy link
Member

Veykril commented Apr 25, 2024

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 25, 2024

📌 Commit aa1f134 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Apr 25, 2024

⌛ Testing commit aa1f134 with merge 65eda41...

@bors
Copy link
Collaborator

bors commented Apr 25, 2024

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing 65eda41 to master...

@bors bors merged commit 65eda41 into rust-lang:master Apr 25, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

hover a struct can't show its whole definition,but hover a enum can
7 participants