-
Notifications
You must be signed in to change notification settings - Fork 123
feat: add code action to generate match
cases
#1307
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
base: main
Are you sure you want to change the base?
Conversation
Also adds some definitions for trying it out in CodeAction.lean Left debug prints in (commented out) - remove these later.
are the underscores in CodeAction.lean a problem? I used this file to put some examples there |
I'm not sure it's possible but is there a way to add test cases for this? |
I don't know, but i believe not, since i don't see any tests for other code actions. Also since code actions are a vscode feature, existence of any testing automation would be unlikely. |
i have removed the issues with the long lines. It builds locally for me now. |
You can run |
ah good to know. The function is defined at |
Co-authored-by: François G. Dorais <[email protected]>
Thank you, very good fix! |
Mathlib CI status (docs):
|
match
(to autogenerate constructor match cases)match
cases
A few questions and comments: The full match syntax is described here. The match syntax supports discriminants that are just terms and also ident : term. Is the latter supported? Is there a way to support multiple discriminants? That would be helpful since it is time consuming to get all the cases for these. Is there a reasonable way to support match n with
| 0 => _
| _ + 1 => _ than match n with
| .zero => _
| .succ _ => _ None of these are deal breakers but they would be great to have. |
def myfun2 (n:Nat) (m:Nat): Nat :=
match n,m with
| .zero, .zero => 0
| .zero, .succ m' => 1
| .succ n', .zero => 2
| .succ n', .succ m' => 3 |
…ear even with (multiple) identifiers and discriminants and a motive in the match expression (motive is ignored by the action. Likewise only the first discriminant is used.
|
This is excellent! There's an issue with placeholder names: example (l r : List Nat) : Empty :=
match l, r with gives this: example (l r : List Nat) : Empty :=
match l, r with
| [], [] => _
| [], head :: tail => _
| head :: tail, [] => _
| head :: tail, head :: tail => _ This is not valid because I don't think it's a burden on users to edit the pattern names (they probably will want to do that anyway). But there probably is a better automatic disambiguation solution, especially one that would make it easier to use find/replace instead of manual editing. What do you think? |
By the way, the CodeAction.Misc file is getting long. It would be great if you could move the match stuff to a CodeAction.Match file. |
A small adaption of the existing code action for holes in this Situation:
gives us a code action that works for
and produces: