Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Fix printing of trailing comments on constructor part of Ppat_construct. #378

Merged
merged 1 commit into from
Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/res_comments_table.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,11 @@ and walkExprArgument (_argLabel, expr) t comments =
| Ppat_construct (constr, Some pat) ->
let (leading, trailing) = partitionLeadingTrailing comments constr.loc in
attach t.leading constr.loc leading;
let (leading, inside, trailing) = partitionByLoc trailing pat.ppat_loc in
let (afterConstructor, rest) =
partitionAdjacentTrailing constr.loc trailing
in
attach t.trailing constr.loc afterConstructor;
let (leading, inside, trailing) = partitionByLoc rest pat.ppat_loc in
attach t.leading pat.ppat_loc leading;
walkPattern pat t inside;
attach t.trailing pat.ppat_loc trailing
Expand Down
2 changes: 1 addition & 1 deletion src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2164,7 +2164,7 @@ and printPattern (p : Parsetree.pattern) cmtTbl =
])
)
| Ppat_construct(constrName, constructorArgs) ->
let constrName = printLongident constrName.txt in
let constrName = printLongidentLocation constrName cmtTbl in
let argsDoc = match constructorArgs with
| None -> Doc.nil
| Some({ppat_loc; ppat_desc = Ppat_construct ({txt = Longident.Lident "()"}, _)}) ->
Expand Down
7 changes: 6 additions & 1 deletion tests/printer/comments/expected/pattern.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ let Black(// singleLineComment

let module(/* c0 */ X /* c1 */: /* c2 */ X_int /* c3 */) /* c4 */ = x

let /* before */ Rgb(
let /* before */ Rgb /* after constr */(
/* red */ r /* red2 */,
/* green */ g /* green2 */,
/* blue */ b /* blue2 */,
) /* after */ = color

switch a {
| Constr /* after constr */
| Constr /* after constr */(a, _) => a
}

let () = ()
let [/* inside */] = []
let list{/* inside */} = list{}
Expand Down
5 changes: 5 additions & 0 deletions tests/printer/comments/pattern.res
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ let module(/* c0 */ X /* c1 */ : /* c2 */ X_int /* c3 */) /* c4 */ = x

let /* before */ Rgb /* after constr */ (/* red */ r /* red2 */, /* green */ g/* green2 */, /* blue */ b /* blue2 */) /* after */ = color

switch a {
| Constr /* after constr */
| Constr /* after constr */ (a, _) => a
}

let () = ()
let [/* inside */] = []
let list{/* inside */} = list{}
Expand Down