@@ -88,7 +88,13 @@ let log t =
88
88
let attach tbl loc comments =
89
89
match comments with
90
90
| [] -> ()
91
- | comments -> Hashtbl. replace tbl loc comments
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
92
98
93
99
(* Partitions a list of comments into three groups based on their position relative to a ___location:
94
100
* - leading: comments that end before the ___location's start position
@@ -1208,6 +1214,12 @@ and walk_expression expr t comments =
1208
1214
| Pexp_variant (_label , None) -> ()
1209
1215
| Pexp_variant (_label , Some expr ) -> walk_expression expr t comments
1210
1216
| 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;
1211
1223
walk_list (exprs |> List. map (fun e -> Expression e)) t comments
1212
1224
| Pexp_record (rows , spread_expr ) ->
1213
1225
if rows = [] then attach t.inside expr.pexp_loc comments
@@ -1540,34 +1552,81 @@ and walk_expression expr t comments =
1540
1552
when Res_parsetree_viewer. is_tuple_array key_values ->
1541
1553
walk_list [Expression key_values] t comments
1542
1554
| Pexp_apply {funct = call_expr ; args = arguments } ->
1543
- let before, inside, after = partition_by_loc comments call_expr.pexp_loc in
1544
- let after =
1545
- if is_block_expr call_expr then (
1546
- let after_expr, rest =
1547
- partition_adjacent_trailing call_expr.pexp_loc after
1548
- in
1549
- walk_expression call_expr t (List. concat [before; inside; after_expr]);
1550
- rest)
1551
- else (
1552
- attach t.leading call_expr.pexp_loc before;
1553
- walk_expression call_expr t inside;
1554
- after)
1555
- in
1556
- let after_expr, rest =
1557
- partition_adjacent_trailing call_expr.pexp_loc after
1558
- in
1559
- attach t.trailing call_expr.pexp_loc after_expr;
1560
- walk_list
1561
- (arguments
1562
- |> List. map (fun (lbl , expr ) ->
1563
- let loc =
1564
- match lbl with
1565
- | Asttypes. Labelled {loc} | Optional {loc} ->
1566
- {loc with loc_end = expr.Parsetree. pexp_loc.loc_end}
1567
- | _ -> expr.pexp_loc
1568
- in
1569
- ExprArgument {expr; loc}))
1570
- t rest
1555
+ (* 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" )}
1558
+ 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)
1600
+ | _ ->
1601
+ (* Regular apply handling *)
1602
+ let before, inside, after = partition_by_loc comments call_expr.pexp_loc in
1603
+ let after =
1604
+ if is_block_expr call_expr then (
1605
+ let after_expr, rest =
1606
+ partition_adjacent_trailing call_expr.pexp_loc after
1607
+ in
1608
+ walk_expression call_expr t (List. concat [before; inside; after_expr]);
1609
+ rest)
1610
+ else (
1611
+ attach t.leading call_expr.pexp_loc before;
1612
+ walk_expression call_expr t inside;
1613
+ after)
1614
+ in
1615
+ let after_expr, rest =
1616
+ partition_adjacent_trailing call_expr.pexp_loc after
1617
+ in
1618
+ attach t.trailing call_expr.pexp_loc after_expr;
1619
+ walk_list
1620
+ (arguments
1621
+ |> List. map (fun (lbl , expr ) ->
1622
+ let loc =
1623
+ match lbl with
1624
+ | Asttypes. Labelled {loc} | Optional {loc} ->
1625
+ {loc with loc_end = expr.Parsetree. pexp_loc.loc_end}
1626
+ | _ -> expr.pexp_loc
1627
+ in
1628
+ ExprArgument {expr; loc}))
1629
+ t rest)
1571
1630
| Pexp_fun _ | Pexp_newtype _ -> (
1572
1631
let _, parameters, return_expr = fun_expr expr in
1573
1632
let comments =
0 commit comments