Skip to content

Commit

Permalink
in-progress
Browse files Browse the repository at this point in the history
  • Loading branch information
7h3kk1d committed Nov 21, 2024
1 parent 7166f28 commit 4ac3b80
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions src/haz3lweb/view/CursorInspector.re
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ let common_err_view =

let common_ok_view =
(
~statics,
~lifted_ty: option(Typ.t)=?,
~sugar_info: option(Info.sugar)=?,
cls: Cls.t,
Expand Down Expand Up @@ -231,7 +232,8 @@ let typ_err_view = (ok: Info.error_typ) =>
]
};

let rec exp_view = (cls: Cls.t, status: Info.status_exp, info: Info.exp) =>
let rec exp_view =
(~statics, cls: Cls.t, status: Info.status_exp, info: Info.exp) =>
switch (status) {
| InHole(FreeVariable(name)) => div_err([code(name), text("not found")])
| InHole(InexhaustiveMatch(additional_err)) =>
Expand All @@ -241,7 +243,7 @@ let rec exp_view = (cls: Cls.t, status: Info.status_exp, info: Info.exp) =>
| Some(err) =>
let cls_str = String.uncapitalize_ascii(cls_str);
div_err([
exp_view(cls, InHole(Common(err)), info),
exp_view(~statics, cls, InHole(Common(err)), info),
text("; " ++ cls_str ++ " is inexhaustive"),
]);
};
Expand Down Expand Up @@ -275,6 +277,7 @@ let rec exp_view = (cls: Cls.t, status: Info.status_exp, info: Info.exp) =>
| NotInHole(Common(ok)) =>
div_ok(
common_ok_view(
~statics,
~lifted_ty=?info.lifted_ty,
~sugar_info=?info.sugar_info,
cls,
Expand All @@ -283,17 +286,20 @@ let rec exp_view = (cls: Cls.t, status: Info.status_exp, info: Info.exp) =>
)
};

let rec pat_view = (cls: Cls.t, status: Info.status_pat) =>
let rec pat_view = (~statics, cls: Cls.t, status: Info.status_pat) =>
switch (status) {
| InHole(ExpectedConstructor) => div_err([text("Expected a constructor")])
| InHole(Redundant(additional_err)) =>
switch (additional_err) {
| None => div_err([text("Pattern is redundant")])
| Some(err) =>
div_err([pat_view(cls, InHole(err)), text("; pattern is redundant")])
div_err([
pat_view(~statics, cls, InHole(err)),
text("; pattern is redundant"),
])
}
| InHole(Common(error)) => div_err(common_err_view(cls, error))
| NotInHole(ok) => div_ok(common_ok_view(cls, ok))
| NotInHole(ok) => div_ok(common_ok_view(~statics, cls, ok))
};

let typ_view = (cls: Cls.t, status: Info.status_typ) =>
Expand Down Expand Up @@ -328,32 +334,38 @@ let tpat_view = (_: Cls.t, status: Info.status_tpat) =>

let secondary_view = (cls: Cls.t) => div_ok([text(cls |> Cls.show)]);

let view_of_info = (~inject, ~settings, ci): list(Node.t) => {
let view_of_info = (~inject, ~settings, ~statics, ci): list(Node.t) => {
print_endline("CI: " ++ Info.show(ci));
let wrapper = status_view => [
term_view(~inject, ~settings, ci),
status_view,
];
switch (ci) {
| Secondary(_) => wrapper(div([]))
| InfoExp({cls, status, _} as ie) => wrapper(exp_view(cls, status, ie))
| InfoExp({cls, status, _} as ie) =>
wrapper(exp_view(~statics, cls, status, ie))
| InfoPat({cls, status, _}) => wrapper(pat_view(cls, status))
| InfoTyp({cls, status, _}) => wrapper(typ_view(cls, status))
| InfoTPat({cls, status, _}) => wrapper(tpat_view(cls, status))
};
};

let inspector_view = (~inject, ~settings, ci): Node.t =>
let inspector_view = (~inject, ~settings, ~statics, ci): Node.t =>
div(
~attrs=[
Attr.id("cursor-inspector"),
clss([Info.is_error(ci) ? errc : okc]),
],
view_of_info(~inject, ~settings, ci),
view_of_info(~inject, ~settings, ~statics, ci),
);

let view =
(~inject, ~settings: Settings.t, editor, cursor_info: option(Info.t)) => {
(
~inject,
~settings: Settings.t,
editor: Editor.t,
cursor_info: option(Info.t),
) => {
let bar_view = div(~attrs=[Attr.id("bottom-bar")]);
let err_view = err =>
bar_view([
Expand All @@ -367,7 +379,12 @@ let view =
| None => err_view("Whitespace or Comment")
| Some(ci) =>
bar_view([
inspector_view(~inject, ~settings, ci),
inspector_view(
~inject,
~settings,
~statics=editor.state.meta.statics,
ci,
),
ProjectorView.Panel.view(
~inject=a => inject(PerformAction(Project(a))),
editor,
Expand Down

0 comments on commit 4ac3b80

Please sign in to comment.