-
Notifications
You must be signed in to change notification settings - Fork 373
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
[Merged by Bors] - feat: tweak calc widget #22170
Conversation
First make the help text clearer for people who do not know how to select stuff in the info view (in VSCode or lean4web) by mentioning Shift-click. Then make the indentation handling more robust to various calc layouts. Also introduces a calc? tactic to complement the calc code action. The issues with the calc code action are: 1) it requires a valid calc syntax so writing calc is not enough. I typically write calc _ to get the code action. But when you write calc and there is already something below that could vaguely be mistaken for a calc then the code action triggers and the replacement swallows the following syntax. 2) A code action is less visible than a TryThis (but this wouldn’t be enough motivation for me without the previous point).
PR summary 295dd76460Import changes exceeding 2%
|
File | Base Count | Head Count | Change |
---|---|---|---|
Mathlib.Tactic.Widget.Calc | 31 | 32 | +1 (+3.23%) |
Import changes for all files
Files | Import difference |
---|---|
Mathlib.Tactic.Widget.Calc |
1 |
Declarations diff
No declarations were harmed in the making of this PR! 🐙
You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>
## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>
The doc-module for script/declarations_diff.sh
contains some details about this script.
No changes to technical debt.
You can run this locally as
./scripts/technical-debt-metrics.sh pr_summary
- The
relative
value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic. - The
absolute
value is therelative
value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).
Mathlib/Tactic/Widget/Calc.lean
Outdated
|
||
open Lean Meta Tactic TryThis in | ||
/-- Create a `calc` proof. -/ | ||
elab stx:"calc?" : tactic => do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test for this with guard_msgs
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Mathlib/Tactic/Widget/Calc.lean
Outdated
let s := s!"calc\n{spc}{goalFmt} := by sorry" | ||
addSuggestions (← getRef) #[.suggestion s] (header := "Create calc tactic:") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to construct this from a TSyntax
object than from a string; was there a reason you didn't do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is
let s := s!"calc\n{spc}{goalFmt} := by sorry" | |
addSuggestions (← getRef) #[.suggestion s] (header := "Create calc tactic:") | |
let s ← `(tactic| calc $(← Lean.PrettyPrinter.delab (← getMainTarget)) := by sorry) | |
addSuggestions (← getRef) #[.suggestion s] (header := "Create calc tactic:") |
(and remove all the unused code prior to this line)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(there is a bug, leanprover/lean4#7191, in the #guard_msgs
result, but the widget works correctly)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I specifically want to handle spaces here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to my test, the Syntax
version already handles the spaces correctly for you in all the ways that matter (everything but guard_msgs
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case it is helpful, my local test also displays the wrong spacing, but the action really inserts the correct indentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case it is helpful, my local test also displays the wrong spacing,
I think it is worth reporting this upstream, but I don't think it is worth working around in this PR. In fact, the workaround here is actually broken if goalFmt
contains a newline, but (I assume) works correctly with my suggestion.
Can you add tests for those cases? |
I’m afraid I don’t have such case at hand. You need student superpowers to trigger such bugs. |
Co-authored-by: damiano <[email protected]>
Co-authored-by: damiano <[email protected]>
I am happy with the current state of the PR. I have not used widgets much myself, but I imagine that the current PR at least fixes some issues that Patrick saw! The only remaining issue is the indention: I prefer Eric's solution, but given that it is interlaced with a displaying bug that appears to produce the wrong indentation, maybe you can leave the code as is, but add a comment mentioning leanprover/lean4#7191 and the |
This results in correct wrapping of the inserted text for multiline suggestions. Unfortunately, `#guard_msgs` renders things misleading, but there is an upstream patch that will fix that.
To make things easier for you, the last commit I pushed switches to my version, and shows the effect of it on some new tests I added. If you feel really strongly, then feel free to revert that commit (and add the comments @adomani requests in its place). |
I don’t care about |
In that case bors merge |
First make the help text clearer for people who do not know how to select stuff in the info view (in VSCode or lean4web) by mentioning Shift-click. Then make the indentation handling more robust to various calc layouts. Also introduces a calc? tactic to complement the calc code action. The issues with the calc code action are: 1) it requires a valid calc syntax so writing calc is not enough. I typically write calc _ to get the code action. But when you write calc and there is already something below that could vaguely be mistaken for a calc then the code action triggers and the replacement swallows the following syntax. 2) A code action is less visible than a TryThis (but this wouldn’t be enough motivation for me without the previous point). Also get rid of two `unreachable!` since experience show that those branches can be reached when handling malformed inputs, and the panic is awful for users. Co-authored-by: Eric Wieser <[email protected]>
Pull request successfully merged into master. Build succeeded: |
* origin/master: feat(Polynomial): polynomial sequences are bases for R[X] (#20846) feat: monoidal structure on Hopf algebras (#12011) feat(DiscreteValuationRing): addVal_eq_zero_iff (#21154) refactor(Cache): refactor getPackageDir to not use manually provided package directories (#21817) feat(CategoryTheory): categories of homological complexes have a separator (#20229) chore(Data/Complex): deprecate `Complex.abs` (#21995) feat: uncountable instances for `Ordinal` and isomorphic types (#18547) feat(Data/Set/Card): a few missing lemmas (#22186) feat: discrete topological spaces are 0-manifolds (#22105) feat(Data/Matroid/Loop): matroid loops (#22045) feat(SetTheory/Ordinal/Nimber/Field): Nimber division (#19066) feat(LinearAlgebra/Pi): add `pi_proj` and `pi_proj_comp` (#22162) feat(Data/Matroid/Circuit): matroid cocircuits (#21692) feat(Topology/Compactification/OnePoint): generalize instance (#22179) feat(Combinatorics/SimpleGraph): takeUntil properties (#21250) feat(Tactic): `pnat_to_nat` and `enat_to_nat` tactics (#21602) refactor: move `Polynomial.coeffs` and related results (#22225) chore: add AlgHom.ker_coe_equiv, resolve porting notes and erws (#22019) refactor(Order/Category): `ConcreteCategory` instance for `\omegaCPO` (#21478) feat(CategoryTheory): Grothendieck categories have a coseparator (#22224) feat: tweak calc widget (#22170) feat(CategoryTheory): the Freyd-Mitchell embedding theorem (#22222) chore(CategoryTheory): turn more `simp` into `simps!` (#22223) feat(CategoryTheory): the category of ind-objects is Grothendieck abelian (#21606) feat(AlgebraicTopology/SimplexCategory/GeneratorsRelations/EpiMono): epi-mono factorisation in `SimplexCategoryGenRel` (#21743) chore(CategoryTheory/DiscreteCategory): turn `simp` to `simps!` (#22217) feat(Analysis/Asymptotics): exponential growth of a sequence (#21178) feat(CategoryTheory): sigmaConst preserves monomorphisms (#21599) feat(RingTheory/Cotangent): `liftBaseChange` is injective for localizations (#21037) chore(CategoryTheory): fix incorrect name (#22210) feat(CategoryTheory): `IsPullback` version of 'pullback of iso is iso' (#22211) feat(CategoryTheory): pullbacks in functor categories (#22209) feat(CategoryTheory): detecting limit cones over connected diagrams (#22192) feat(LinearAlgebra): add theorems for injective/surjective/bijective compositions of bilinear maps (#21491)
First make the help text clearer for people who do not know how to select stuff in the info view (in VSCode or lean4web) by mentioning Shift-click. Then make the indentation handling more robust to various calc layouts. Also introduces a calc? tactic to complement the calc code action. The issues with the calc code action are: 1) it requires a valid calc syntax so writing calc is not enough. I typically write calc _ to get the code action. But when you write calc and there is already something below that could vaguely be mistaken for a calc then the code action triggers and the replacement swallows the following syntax. 2) A code action is less visible than a TryThis (but this wouldn’t be enough motivation for me without the previous point). Also get rid of two `unreachable!` since experience show that those branches can be reached when handling malformed inputs, and the panic is awful for users. Co-authored-by: Eric Wieser <[email protected]>
First make the help text clearer for people who do not know how to select stuff in the info view (in VSCode or lean4web) by mentioning Shift-click.
Then make the indentation handling more robust to various calc layouts.
Also introduces a calc? tactic to complement the calc code action. The issues with the calc code action are:
typically write calc _ to get the code action. But when you write
calc and there is already something below that could vaguely be
mistaken for a calc then the code action triggers and the replacement
swallows the following syntax.
enough motivation for me without the previous point).
Also get rid of two
unreachable!
since experience show that those branches can be reached when handling malformed inputs, and the panic is awful for users.