Skip to content

Commit fff8d95

Browse files
authored
Handle merlin typed holes (#1698)
1 parent b4fed06 commit fff8d95

37 files changed

+232
-130
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#### New features
1212

13+
+ Handle merlin typed holes (#1698, @gpetiot)
14+
1315
### 0.19.0 (2021-07-16)
1416

1517
#### Bug fixes

lib/Ast.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ let rec mty_is_simple x =
404404

405405
and mod_is_simple x =
406406
match x.pmod_desc with
407-
| Pmod_ident _ | Pmod_unpack _ | Pmod_structure [] -> true
407+
| Pmod_ident _ | Pmod_unpack _ | Pmod_structure [] | Pmod_hole -> true
408408
| Pmod_structure (_ :: _) | Pmod_extension _ | Pmod_functor (_, _) -> false
409409
| Pmod_constraint (e, t) -> mod_is_simple e && mty_is_simple t
410410
| Pmod_apply (a, b) -> mod_is_simple a && mod_is_simple b
@@ -1338,7 +1338,7 @@ end = struct
13381338
|Pexp_newtype _ | Pexp_open _ | Pexp_override _ | Pexp_pack _
13391339
|Pexp_poly _ | Pexp_record _ | Pexp_send _ | Pexp_sequence _
13401340
|Pexp_setfield _ | Pexp_setinstvar _ | Pexp_tuple _
1341-
|Pexp_unreachable | Pexp_variant _ | Pexp_while _ ->
1341+
|Pexp_unreachable | Pexp_variant _ | Pexp_while _ | Pexp_hole ->
13421342
assert false
13431343
| Pexp_extension (_, ext) -> assert (check_extensions ext)
13441344
| Pexp_object {pcstr_self; pcstr_fields} ->
@@ -1434,7 +1434,7 @@ end = struct
14341434
assert (e1 == exp || e2 == exp)
14351435
| Pexp_extension (_, ext) -> assert (check_extensions ext)
14361436
| Pexp_constant _ | Pexp_ident _ | Pexp_new _ | Pexp_pack _
1437-
|Pexp_unreachable ->
1437+
|Pexp_unreachable | Pexp_hole ->
14381438
assert false
14391439
| Pexp_object {pcstr_fields; _} ->
14401440
assert (check_pcstr_fields pcstr_fields)
@@ -2108,7 +2108,7 @@ end = struct
21082108
|Pexp_new _ | Pexp_object _ | Pexp_override _ | Pexp_pack _
21092109
|Pexp_poly _ | Pexp_record _ | Pexp_send _ | Pexp_unreachable
21102110
|Pexp_variant (_, None)
2111-
|Pexp_while _ ->
2111+
|Pexp_hole | Pexp_while _ ->
21122112
false
21132113
in
21142114
Exp.mem_cls cls exp
@@ -2186,7 +2186,7 @@ end = struct
21862186
|Pexp_new _ | Pexp_object _ | Pexp_override _ | Pexp_pack _
21872187
|Pexp_poly _ | Pexp_record _ | Pexp_send _ | Pexp_unreachable
21882188
|Pexp_variant (_, None)
2189-
|Pexp_while _ ->
2189+
|Pexp_hole | Pexp_while _ ->
21902190
false
21912191
in
21922192
Hashtbl.find_or_add marked_parenzed_inner_nested_match exp

lib/Fmt_ast.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ let update_items_config c items update_config =
198198

199199
let box_semisemi b k = hvbox_if b 0 (k $ fmt_if b "@,;;")
200200

201+
let fmt_hole () = str "_"
202+
201203
let fmt_item_list c ctx update_config ast fmt_item items =
202204
let items = update_items_config c items update_config in
203205
let break_struct = c.conf.break_struct || is_top ctx in
@@ -2572,6 +2574,7 @@ and fmt_expression c ?(box = true) ?pro ?epi ?eol ?parens ?(indent_wrap = 0)
25722574
$ fmt_atrs ) )
25732575
| Pexp_poly _ ->
25742576
impossible "only used for methods, handled during method formatting"
2577+
| Pexp_hole -> hvbox 0 (fmt_hole () $ fmt_atrs)
25752578

25762579
and fmt_let_bindings c ~ctx ?ext ~parens ~loc ~attributes ~fmt_atrs ~fmt_expr
25772580
rec_flag bindings body =
@@ -4124,6 +4127,14 @@ and fmt_module_expr ?(can_break_before_struct = false) c ({ast= m; _} as xmod)
41244127
( fmt_docstring c ~epi:(fmt "@,") doc
41254128
$ fmt_extension c ctx "%" x1
41264129
$ fmt_attributes c ~pre:Space ~key:"@" atrs ) }
4130+
| Pmod_hole ->
4131+
let doc, atrs = doc_atrs pmod_attributes in
4132+
{ empty with
4133+
bdy=
4134+
Cmts.fmt c pmod_loc
4135+
( fmt_docstring c ~epi:(fmt "@,") doc
4136+
$ fmt_hole ()
4137+
$ fmt_attributes c ~pre:Space ~key:"@" atrs ) }
41274138

41284139
and fmt_structure c ctx itms =
41294140
let update_config c i =

test/failing/dune.inc

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,6 @@
7777
(package ocamlformat)
7878
(action (diff tests/exprs.ml.broken-ref exprs.ml.output)))
7979

80-
(rule
81-
(deps tests/.ocamlformat )
82-
(package ocamlformat)
83-
(action
84-
(with-outputs-to ifand.ml.output
85-
(with-accepted-exit-codes 1
86-
(run %{bin:ocamlformat} %{dep:tests/ifand.ml})))))
87-
88-
(rule
89-
(alias runtest)
90-
(package ocamlformat)
91-
(action (diff tests/ifand.ml.broken-ref ifand.ml.output)))
92-
9380
(rule
9481
(deps tests/.ocamlformat )
9582
(package ocamlformat)
@@ -129,19 +116,6 @@
129116
(package ocamlformat)
130117
(action (diff tests/js_bench.ml.broken-ref js_bench.ml.output)))
131118

132-
(rule
133-
(deps tests/.ocamlformat )
134-
(package ocamlformat)
135-
(action
136-
(with-outputs-to js_bind.ml.output
137-
(with-accepted-exit-codes 1
138-
(run %{bin:ocamlformat} %{dep:tests/js_bind.ml})))))
139-
140-
(rule
141-
(alias runtest)
142-
(package ocamlformat)
143-
(action (diff tests/js_bind.ml.broken-ref js_bind.ml.output)))
144-
145119
(rule
146120
(deps tests/.ocamlformat )
147121
(package ocamlformat)
@@ -194,32 +168,6 @@
194168
(package ocamlformat)
195169
(action (diff tests/js_low_priority.ml.broken-ref js_low_priority.ml.output)))
196170

197-
(rule
198-
(deps tests/.ocamlformat )
199-
(package ocamlformat)
200-
(action
201-
(with-outputs-to js_map.ml.output
202-
(with-accepted-exit-codes 1
203-
(run %{bin:ocamlformat} %{dep:tests/js_map.ml})))))
204-
205-
(rule
206-
(alias runtest)
207-
(package ocamlformat)
208-
(action (diff tests/js_map.ml.broken-ref js_map.ml.output)))
209-
210-
(rule
211-
(deps tests/.ocamlformat )
212-
(package ocamlformat)
213-
(action
214-
(with-outputs-to js_poly.ml.output
215-
(with-accepted-exit-codes 1
216-
(run %{bin:ocamlformat} %{dep:tests/js_poly.ml})))))
217-
218-
(rule
219-
(alias runtest)
220-
(package ocamlformat)
221-
(action (diff tests/js_poly.ml.broken-ref js_poly.ml.output)))
222-
223171
(rule
224172
(deps tests/.ocamlformat )
225173
(package ocamlformat)
@@ -324,32 +272,6 @@
324272
(package ocamlformat)
325273
(action (diff tests/never_align.ml.broken-ref never_align.ml.output)))
326274

327-
(rule
328-
(deps tests/.ocamlformat )
329-
(package ocamlformat)
330-
(action
331-
(with-outputs-to object.ml.output
332-
(with-accepted-exit-codes 1
333-
(run %{bin:ocamlformat} %{dep:tests/object.ml})))))
334-
335-
(rule
336-
(alias runtest)
337-
(package ocamlformat)
338-
(action (diff tests/object.ml.broken-ref object.ml.output)))
339-
340-
(rule
341-
(deps tests/.ocamlformat )
342-
(package ocamlformat)
343-
(action
344-
(with-outputs-to obuild.ml.output
345-
(with-accepted-exit-codes 1
346-
(run %{bin:ocamlformat} %{dep:tests/obuild.ml})))))
347-
348-
(rule
349-
(alias runtest)
350-
(package ocamlformat)
351-
(action (diff tests/obuild.ml.broken-ref obuild.ml.output)))
352-
353275
(rule
354276
(deps tests/.ocamlformat )
355277
(package ocamlformat)
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ocamlformat: ignoring "tests/edge_cases.ml" (syntax error)
2-
File "tests/edge_cases.ml", line 21, characters 4-5:
3-
21 | _
4-
^
5-
Error: Syntax error: wildcard "_" not expected.
2+
File "tests/edge_cases.ml", line 90, characters 4-12:
3+
90 | function (_ : [ `c ]) -> d
4+
^^^^^^^^
5+
Error: Syntax error

test/failing/tests/ifand.ml.broken-ref

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/failing/tests/js_bind.ml.broken-ref

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/failing/tests/js_map.ml.broken-ref

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/failing/tests/js_poly.ml.broken-ref

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/failing/tests/object.ml.broken-ref

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)