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

fix: consistently show non-mvar term in hovertext #5368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Aaron1011
Copy link

Previously, the hover text would only show the term in the hovertext if the pretty-printed text was 'atomic', which excluded expressions like 1 + 1.
This made the hovertext less useful for inspecting an underscore (_), since only the type (and not the term) would be displayed for a complex expression.

Change the behavior to hide the term if it's a single metavariable, and otherwise display both the term and type. This ensures that we do not produce unhelpful hovertext like ?m : SomeType (we still produce just SomeType).

We now display both the term and type in a few other cases - this makes the output a little more verbose, but also ensures that users can see resolved metavariables in the term.

Closes #5367

Previously, the hover text would only show the term
in the hovertext if the pretty-printed text was 'atomic',
which excluded expressions like `1 + 1`.
This made the hovertext less useful for inspecting an underscore (`_`),
since only the type (and not the term) would be displayed
for a complex expression.

Change the behavior to hide the term if it's a single
metavariable, and otherwise display both the term and type.
This ensures that we do not produce unhelpful hovertext
like `?m : SomeType` (we still produce just `SomeType`).

We now display both the term and type in a few other cases -
this makes the output a little more verbose, but also ensures
that users can see resolved metavariables in the term.

Closes leanprover#5367
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Sep 16, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 445c8f2ee02ec75cdd8b2811bd56f4fb16adb655 --onto c25d2066471c7726b64d7f3eea8b5cce9910f33d. (2024-09-16 21:55:28)

@@ -316,7 +316,7 @@ where
if let some ldecl := (← getLCtx).findFVar? e then
!ldecl.userName.hasMacroScopes
else false
else isAtomicFormat eFmt
else !e.isMVar
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure that you want to check for isMVar here? What about applications of an MVar to another MVar, for example?

Copy link
Author

Choose a reason for hiding this comment

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

My thinking is while showing something like ?m : SomeType doesn't really provide any useful information, it's better to err on the side of showing more information about inference for more complicated types.

Applying an MVar to an MVar would come from something like _ _, right? I think it would be useful to be able to explicitly see when Lean isn't able to infer terms for MVars in that kind of expression.

Comment on lines -328 to -333
isAtomicFormat : Format → Bool
| Std.Format.text _ => true
| Std.Format.group f _ => isAtomicFormat f
| Std.Format.nest _ f => isAtomicFormat f
| Std.Format.tag _ f => isAtomicFormat f
| _ => false
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that we want to delete this in general. It was originally introduced to avoid cluttering the hover panel with information already present below the cursor in non-_ hover cases (e.g. the test cases in 4078.lean) and I would like to retain that.

Copy link
Author

Choose a reason for hiding this comment

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

Do you want this to still be used in this pr, or just kept around (unused) for future use?
My concern is that this heuristic can result in more-important expressions being hidden from the user - I first noticed this issue when looking at an _ that was inferred to (p - 1) / q, which was harder for me to deduce by hand than if the term was something simpler like p.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, the inferred expression would not be hidden away when hovering over _, but is hidden away in all other cases to avoid cluttering the hover panel with redundant information.

@leanprover-bot leanprover-bot added the P-low We are not planning to work on this issue label Sep 20, 2024
@mhuisi mhuisi added the awaiting-author Waiting for PR author to address issues label Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-author Waiting for PR author to address issues P-low We are not planning to work on this issue toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hovering over underscore (_) shows type, but not term
4 participants