Skip to content

Commit 10a878a

Browse files
committed
Remove loc adjustment hack
1 parent efc4ca1 commit 10a878a

File tree

2 files changed

+14
-38
lines changed

2 files changed

+14
-38
lines changed

compiler/syntax/src/res_core.ml

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4905,28 +4905,14 @@ and parse_type_constructor_declaration_with_bar p =
49054905
[doc_comment_to_attribute loc s]
49064906
| _ -> []
49074907
in
4908-
let has_doc_comment = not (doc_comment_attrs = []) in
49094908
let start_pos = p.Parser.start_pos in
49104909
Parser.next p;
49114910
let constr = parse_type_constructor_declaration ~start_pos p in
4912-
let pcd_loc =
4913-
if has_doc_comment then
4914-
{
4915-
constr.Parsetree.pcd_loc with
4916-
loc_end =
4917-
{
4918-
constr.pcd_loc.loc_end with
4919-
pos_lnum = constr.pcd_loc.loc_end.pos_lnum + 1;
4920-
};
4921-
}
4922-
else constr.pcd_loc
4923-
in
49244911
Some
49254912
{
49264913
constr with
49274914
Parsetree.pcd_attributes =
49284915
doc_comment_attrs @ constr.Parsetree.pcd_attributes;
4929-
pcd_loc;
49304916
}
49314917
| _ -> None
49324918

@@ -4964,27 +4950,10 @@ and parse_type_constructor_declarations ?first p =
49644950
[doc_comment_to_attribute loc s]
49654951
| _ -> []
49664952
in
4967-
let has_doc_comment = not (doc_comment_attrs = []) in
49684953
let start_pos = p.Parser.start_pos in
49694954
ignore (Parser.optional p Token.Bar);
49704955
let constr = parse_type_constructor_declaration ~start_pos p in
4971-
let pcd_loc =
4972-
if has_doc_comment then
4973-
{
4974-
constr.Parsetree.pcd_loc with
4975-
loc_end =
4976-
{
4977-
constr.pcd_loc.loc_end with
4978-
pos_lnum = constr.pcd_loc.loc_end.pos_lnum + 1;
4979-
};
4980-
}
4981-
else constr.pcd_loc
4982-
in
4983-
{
4984-
constr with
4985-
pcd_attributes = doc_comment_attrs @ constr.pcd_attributes;
4986-
pcd_loc;
4987-
}
4956+
{constr with pcd_attributes = doc_comment_attrs @ constr.pcd_attributes}
49884957
| Some first_constr_decl -> first_constr_decl
49894958
in
49904959
first_constr_decl

compiler/syntax/src/res_printer.ml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ let print_list ~get_loc ~nodes ~print ?(force_break = false) t =
340340
in
341341
Doc.breakable_group ~force_break docs
342342

343-
let print_listi ~get_loc ~nodes ~print ?(force_break = false) t =
343+
let print_listi ~get_loc ~nodes ~print ?(ignore_empty_lines = false)
344+
?(force_break = false) t =
344345
let rec loop i (prev_loc : Location.t) acc nodes =
345346
match nodes with
346347
| [] -> (prev_loc, Doc.concat (List.rev acc))
@@ -352,8 +353,10 @@ let print_listi ~get_loc ~nodes ~print ?(force_break = false) t =
352353
| Some comment -> (Comment.loc comment).loc_start
353354
in
354355
let sep =
355-
if start_pos.pos_lnum - prev_loc.loc_end.pos_lnum > 1 then
356-
Doc.concat [Doc.hard_line; Doc.hard_line]
356+
if
357+
start_pos.pos_lnum - prev_loc.loc_end.pos_lnum > 1
358+
&& not ignore_empty_lines
359+
then Doc.concat [Doc.hard_line; Doc.hard_line]
357360
else Doc.line
358361
in
359362
let doc = print_comments (print node t i) t loc in
@@ -1542,18 +1545,22 @@ and print_constructor_declarations ~state ~private_flag
15421545
~print:(fun cd cmt_tbl i ->
15431546
let doc = print_constructor_declaration2 ~state i cd cmt_tbl in
15441547
print_comments doc cmt_tbl cd.Parsetree.pcd_loc)
1545-
~force_break cmt_tbl
1548+
~force_break cmt_tbl ~ignore_empty_lines:true
15461549
in
15471550
Doc.breakable_group ~force_break
15481551
(Doc.indent (Doc.concat [Doc.line; private_flag; rows]))
15491552

15501553
and print_constructor_declaration2 ~state i
15511554
(cd : Parsetree.constructor_declaration) cmt_tbl =
1552-
let comment_attrs, attrs = ParsetreeViewer.partition_doc_comment_attributes cd.pcd_attributes in
1555+
let comment_attrs, attrs =
1556+
ParsetreeViewer.partition_doc_comment_attributes cd.pcd_attributes
1557+
in
15531558
let comment_doc =
15541559
match comment_attrs with
15551560
| [] -> Doc.nil
1556-
| comment_attrs -> print_doc_comments ~sep:Doc.hard_line ~state cmt_tbl comment_attrs in
1561+
| comment_attrs ->
1562+
print_doc_comments ~sep:Doc.hard_line ~state cmt_tbl comment_attrs
1563+
in
15571564
let attrs = print_attributes ~state attrs cmt_tbl in
15581565
let is_dot_dot_dot = cd.pcd_name.txt = "..." in
15591566
let bar =

0 commit comments

Comments
 (0)