Skip to content

Commit

Permalink
Add a new synthetic node for continuations
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos committed Jan 7, 2025
1 parent 5a87184 commit 4695c3a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
26 changes: 24 additions & 2 deletions src/ocaml/merlin_specific/browse_raw.ml
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ let rec of_expression_desc loc = function
| _, None -> id_fold
| _, Some e -> of_expression e)
ls
| Texp_match (e, cs, _, _) -> of_expression e ** list_fold of_case cs
| Texp_match (e, cs, vs, _) ->
of_expression e ** list_fold of_case cs ** list_fold of_case vs
| Texp_try (e, cs, _) -> of_expression e ** list_fold of_case cs
| Texp_tuple es | Texp_construct (_, _, es) | Texp_array es ->
list_fold of_expression es
Expand Down Expand Up @@ -560,7 +561,28 @@ let of_node = function
| Pattern { pat_desc; pat_extra = _ } -> of_pattern_desc pat_desc
| Expression { exp_desc; exp_extra = _; exp_loc } ->
of_expression_desc exp_loc exp_desc
| Case { c_lhs; c_guard; c_rhs } ->
| Case { c_lhs; c_cont = Some (id, vd); c_guard; c_rhs } ->
let vd =
let name = Ident.name id in
Typedtree.
{ val_id = id;
val_name = { txt = name; loc = vd.val_loc };
val_desc =
{ ctyp_desc = Ttyp_var name;
ctyp_type = vd.val_type;
ctyp_env = Env.empty;
ctyp_loc = vd.val_loc;
ctyp_attributes = []
};
val_val = vd;
val_prim = [];
val_loc = vd.val_loc;
val_attributes = []
}
in
of_pattern c_lhs ** of_expression c_rhs ** app (Value_description vd)
** option_fold of_expression c_guard
| Case { c_lhs; c_cont = None; c_guard; c_rhs } ->
of_pattern c_lhs ** of_expression c_rhs ** option_fold of_expression c_guard
| Class_expr { cl_desc } -> of_class_expr_desc cl_desc
| Class_structure { cstr_self; cstr_fields } ->
Expand Down
2 changes: 1 addition & 1 deletion src/ocaml/typing/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6144,7 +6144,7 @@ and type_cases
~type_body:begin
fun { pc_guard; pc_rhs } pat ~when_env ~ext_env ~cont ~ty_expected
~ty_infer ~contains_gadt:_ ->
let cont = Option.map (fun (id,_) -> id) cont in
(* let cont = Option.map (fun (id,_) -> id) cont in *)
let guard =
match pc_guard with
| None -> None
Expand Down
2 changes: 1 addition & 1 deletion src/ocaml/typing/typedtree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ and meth =
and 'k case =
{
c_lhs: 'k general_pattern;
c_cont: Ident.t option;
c_cont: (Ident.t * Types.value_description) option;
c_guard: expression option;
c_rhs: expression;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ocaml/typing/typedtree.mli
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ and meth =
and 'k case =
{
c_lhs: 'k general_pattern;
c_cont: Ident.t option;
c_cont: (Ident.t * Types.value_description) option;
c_guard: expression option;
c_rhs: expression;
}
Expand Down
10 changes: 5 additions & 5 deletions tests/test-dirs/type-enclosing/503-effects.t
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
"tail": "no"
}

FIXME: the continuation is invisible to Merlin
The continuation is visible to Merlin
$ $MERLIN single type-enclosing -position 10:16 \
> -filename main.ml <main.ml | jq '.value[0]'
{
"start": {
"line": 8,
"col": 4
"line": 10,
"col": 16
},
"end": {
"line": 10,
"col": 23
"col": 17
},
"type": "int",
"type": "(%eff, int) continuation",
"tail": "no"
}

0 comments on commit 4695c3a

Please sign in to comment.