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

Added refine for products and arrows #1416

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
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
13 changes: 9 additions & 4 deletions src/haz3lcore/zipper/action/Action.re
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ type t =
| RotateBackpack
| MoveToBackpackTarget(planar)
| Pick_up
| Put_down;
| Put_down
| Refine;

module Failure = {
[@deriving (show({with_path: false}), sexp, yojson)]
Expand All @@ -97,7 +98,8 @@ module Failure = {
| Cant_project
| CantPaste
| CantReparse
| CantAccept;
| CantAccept
| CantRefine;
};

module Result = {
Expand All @@ -114,6 +116,7 @@ let is_edit: t => bool =
| Destruct(_)
| Pick_up
| Put_down
| Refine
| Buffer(Accept | Clear | Set(_)) => true
| Copy
| Move(_)
Expand Down Expand Up @@ -151,7 +154,8 @@ let is_historic: t => bool =
| Insert(_)
| Destruct(_)
| Pick_up
| Put_down => true
| Put_down
| Refine => true
| Project(p) =>
switch (p) {
| SetSyntax(_)
Expand Down Expand Up @@ -179,7 +183,8 @@ let prevent_in_read_only_editor = (a: t) => {
| Pick_up
| Put_down
| RotateBackpack
| MoveToBackpackTarget(_) => true
| MoveToBackpackTarget(_)
| Refine => true
| Project(p) =>
switch (p) {
| SetSyntax(_) => true
Expand Down
27 changes: 27 additions & 0 deletions src/haz3lcore/zipper/action/Perform.re
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,32 @@ let go_z =
module Move = Move.Make(M);
module Select = Select.Make(M);

let refine = (z: Zipper.t) => {
switch (Indicated.ci_of(z, meta.statics.info_map)) {
| None => None
| Some(
InfoExp({
cls: Exp(EmptyHole),
status: NotInHole(Common(Ana(Consistent({ana, _})))),
ctx,
_,
}),
) =>
let z =
Printer.zipper_of_string(
~zipper_init=z,
switch (Typ.term_of(Typ.weak_head_normalize(ctx, ana))) {
| Arrow(_, _) => "fun -> "
| Prod(tys) =>
"(" ++ StringUtil.repeat(List.length(tys) - 1, ", ") ++ ") "
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This ends up adding a trailing space but that also seems to happen in the paste case as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't want extra parens if we're inside of a function application but I don't know how much it matters.

| _ => ""
},
);
Option.map(remold_regrout(Left, _), z);
| _ => None
};
};

let paste = (z: Zipper.t, str: string): option(Zipper.t) => {
open Util.OptUtil.Syntax;
let* z = Printer.zipper_of_string(~zipper_init=z, str);
Expand Down Expand Up @@ -88,6 +114,7 @@ let go_z =
| None => Error(CantPaste)
| Some(z) => Ok(z)
}
| Refine => refine(z) |> Result.of_option(~error=Action.Failure.CantRefine)
| Cut =>
/* System clipboard handling is done in Page.view handlers */
switch (Destruct.go(Left, z)) {
Expand Down
6 changes: 6 additions & 0 deletions src/haz3lweb/Keyboard.re
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ let shortcuts = (sys: Key.sys): list(shortcut) =>
"Run Benchmark",
Benchmark(Start),
),
mk_shortcut(
~mdIcon="bolt",
~section="Refactoring",
"Refine",
PerformAction(Refine),
),
]
@ (if (ExerciseSettings.show_instructor) {instructor_shortcuts} else {[]});

Expand Down
3 changes: 2 additions & 1 deletion src/haz3lweb/UpdateAction.re
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ let should_scroll_to_caret =
| Paste(_)
| Copy
| Cut
| Reparse => true
| Reparse
| Refine => true
| Project(_)
| Unselect(_)
| Select(All) => false
Expand Down
Loading