@@ -88,13 +88,7 @@ let log t =
88
88
let attach tbl loc comments =
89
89
match comments with
90
90
| [] -> ()
91
- | comments ->
92
- Printf. eprintf " DEBUG: Attaching %d comments to ___location [%d:%d-%d:%d]\n "
93
- (List. length comments)
94
- loc.Location. loc_start.pos_lnum (loc.Location. loc_start.pos_cnum - loc.Location. loc_start.pos_bol)
95
- loc.Location. loc_end.pos_lnum (loc.Location. loc_end.pos_cnum - loc.Location. loc_end.pos_bol);
96
- List. iter (fun c -> Printf. eprintf " Comment: %S\n " (Comment. txt c)) comments;
97
- Hashtbl. replace tbl loc comments
91
+ | comments -> Hashtbl. replace tbl loc comments
98
92
99
93
(* Partitions a list of comments into three groups based on their position relative to a ___location:
100
94
* - leading: comments that end before the ___location's start position
@@ -1214,12 +1208,6 @@ and walk_expression expr t comments =
1214
1208
| Pexp_variant (_label , None) -> ()
1215
1209
| Pexp_variant (_label , Some expr ) -> walk_expression expr t comments
1216
1210
| Pexp_array exprs | Pexp_tuple exprs ->
1217
- Printf. eprintf " DEBUG: Processing array/tuple with %d expressions:\n " (List. length exprs);
1218
- List. iteri (fun i e ->
1219
- Printf. eprintf " [%d] Expression at [%d:%d-%d:%d]\n " i
1220
- e.Parsetree. pexp_loc.loc_start.pos_lnum (e.Parsetree. pexp_loc.loc_start.pos_cnum - e.Parsetree. pexp_loc.loc_start.pos_bol)
1221
- e.Parsetree. pexp_loc.loc_end.pos_lnum (e.Parsetree. pexp_loc.loc_end.pos_cnum - e.Parsetree. pexp_loc.loc_end.pos_bol)
1222
- ) exprs;
1223
1211
walk_list (exprs |> List. map (fun e -> Expression e)) t comments
1224
1212
| Pexp_record (rows , spread_expr ) ->
1225
1213
if rows = [] then attach t.inside expr.pexp_loc comments
@@ -1551,55 +1539,66 @@ and walk_expression expr t comments =
1551
1539
}
1552
1540
when Res_parsetree_viewer. is_tuple_array key_values ->
1553
1541
walk_list [Expression key_values] t comments
1554
- | Pexp_apply {funct = call_expr ; args = arguments } ->
1542
+ | Pexp_apply {funct = call_expr ; args = arguments } -> (
1555
1543
(* Special handling for Belt.Array.concatMany - treat like an array *)
1556
- (match call_expr.pexp_desc with
1557
- | Pexp_ident {txt = Longident. Ldot (Longident. Ldot (Longident. Lident " Belt" , " Array" ), " concatMany" )}
1544
+ match call_expr.pexp_desc with
1545
+ | Pexp_ident
1546
+ {
1547
+ txt =
1548
+ Longident. Ldot
1549
+ (Longident. Ldot (Longident. Lident " Belt" , " Array" ), " concatMany" );
1550
+ }
1558
1551
when List. length arguments = 1 -> (
1559
- match arguments with
1560
- | [(_, {pexp_desc = Pexp_array sub_arrays})] ->
1561
- Printf. eprintf " DEBUG: Special handling for Belt.Array.concatMany with %d sub-arrays\n " (List. length sub_arrays);
1562
- (* Collect all individual expressions from sub-arrays *)
1563
- let all_exprs = List. fold_left (fun acc sub_array ->
1564
- match sub_array.Parsetree. pexp_desc with
1565
- | Pexp_array exprs -> acc @ exprs
1566
- | _ -> acc @ [sub_array]
1567
- ) [] sub_arrays in
1568
- Printf. eprintf " DEBUG: Collected %d individual expressions\n " (List. length all_exprs);
1569
- walk_list (all_exprs |> List. map (fun e -> Expression e)) t comments
1570
- | _ ->
1571
- (* Fallback to regular apply handling *)
1572
- let before, inside, after = partition_by_loc comments call_expr.pexp_loc in
1573
- let after =
1574
- if is_block_expr call_expr then (
1575
- let after_expr, rest =
1576
- partition_adjacent_trailing call_expr.pexp_loc after
1577
- in
1578
- walk_expression call_expr t (List. concat [before; inside; after_expr]);
1579
- rest)
1580
- else (
1581
- attach t.leading call_expr.pexp_loc before;
1582
- walk_expression call_expr t inside;
1583
- after)
1584
- in
1585
- let after_expr, rest =
1586
- partition_adjacent_trailing call_expr.pexp_loc after
1587
- in
1588
- attach t.trailing call_expr.pexp_loc after_expr;
1589
- walk_list
1590
- (arguments
1591
- |> List. map (fun (lbl , expr ) ->
1592
- let loc =
1593
- match lbl with
1594
- | Asttypes. Labelled {loc} | Optional {loc} ->
1595
- {loc with loc_end = expr.Parsetree. pexp_loc.loc_end}
1596
- | _ -> expr.pexp_loc
1597
- in
1598
- ExprArgument {expr; loc}))
1599
- t rest)
1552
+ match arguments with
1553
+ | [(_, {pexp_desc = Pexp_array sub_arrays})] ->
1554
+ (* Collect all individual expressions from sub-arrays *)
1555
+ let all_exprs =
1556
+ List. fold_left
1557
+ (fun acc sub_array ->
1558
+ match sub_array.Parsetree. pexp_desc with
1559
+ | Pexp_array exprs -> acc @ exprs
1560
+ | _ -> acc @ [sub_array])
1561
+ [] sub_arrays
1562
+ in
1563
+ walk_list (all_exprs |> List. map (fun e -> Expression e)) t comments
1564
+ | _ ->
1565
+ (* Fallback to regular apply handling *)
1566
+ let before, inside, after =
1567
+ partition_by_loc comments call_expr.pexp_loc
1568
+ in
1569
+ let after =
1570
+ if is_block_expr call_expr then (
1571
+ let after_expr, rest =
1572
+ partition_adjacent_trailing call_expr.pexp_loc after
1573
+ in
1574
+ walk_expression call_expr t
1575
+ (List. concat [before; inside; after_expr]);
1576
+ rest)
1577
+ else (
1578
+ attach t.leading call_expr.pexp_loc before;
1579
+ walk_expression call_expr t inside;
1580
+ after)
1581
+ in
1582
+ let after_expr, rest =
1583
+ partition_adjacent_trailing call_expr.pexp_loc after
1584
+ in
1585
+ attach t.trailing call_expr.pexp_loc after_expr;
1586
+ walk_list
1587
+ (arguments
1588
+ |> List. map (fun (lbl , expr ) ->
1589
+ let loc =
1590
+ match lbl with
1591
+ | Asttypes. Labelled {loc} | Optional {loc} ->
1592
+ {loc with loc_end = expr.Parsetree. pexp_loc.loc_end}
1593
+ | _ -> expr.pexp_loc
1594
+ in
1595
+ ExprArgument {expr; loc}))
1596
+ t rest)
1600
1597
| _ ->
1601
1598
(* Regular apply handling *)
1602
- let before, inside, after = partition_by_loc comments call_expr.pexp_loc in
1599
+ let before, inside, after =
1600
+ partition_by_loc comments call_expr.pexp_loc
1601
+ in
1603
1602
let after =
1604
1603
if is_block_expr call_expr then (
1605
1604
let after_expr, rest =
0 commit comments