@@ -88,13 +88,7 @@ let log t =
8888let attach tbl loc comments =
8989 match comments with
9090 | [] -> ()
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
9892
9993(* Partitions a list of comments into three groups based on their position relative to a location:
10094 * - leading: comments that end before the location's start position
@@ -1214,12 +1208,6 @@ and walk_expression expr t comments =
12141208 | Pexp_variant (_label , None) -> ()
12151209 | Pexp_variant (_label , Some expr ) -> walk_expression expr t comments
12161210 | 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;
12231211 walk_list (exprs |> List. map (fun e -> Expression e)) t comments
12241212 | Pexp_record (rows , spread_expr ) ->
12251213 if rows = [] then attach t.inside expr.pexp_loc comments
@@ -1551,55 +1539,66 @@ and walk_expression expr t comments =
15511539 }
15521540 when Res_parsetree_viewer. is_tuple_array key_values ->
15531541 walk_list [Expression key_values] t comments
1554- | Pexp_apply {funct = call_expr ; args = arguments } ->
1542+ | Pexp_apply {funct = call_expr ; args = arguments } -> (
15551543 (* 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+ }
15581551 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)
16001597 | _ ->
16011598 (* 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
16031602 let after =
16041603 if is_block_expr call_expr then (
16051604 let after_expr, rest =
0 commit comments