Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print newline after doc comments before attributes #1869

Merged
merged 3 commits into from Jun 5, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions formatTest/typeCheckedTests/expected_output/reasonComments.re
Expand Up @@ -721,3 +721,29 @@ let r = {
fieldOne: (identifier: string), /*eol1*/
fieldTwo: (identifier: string) /* eol2 with trailing comma */
};

/** doc comment */
[@bs.send]
external url : t => string = "";

/**
* Short multiline doc comment
*/
[@bs.send]
external url : t => string = "";

/** Longer doc comment before an attribute on an external. */
[@bs.send]
external url : t => string = "";

/* normal comment */
[@bs.send] external url : t => string = "";

/** doc type */
type q = {
a: int,
b: string,
};

/** doc let */
let letter: q = {a: 42, b: "answer"};
23 changes: 23 additions & 0 deletions formatTest/typeCheckedTests/input/reasonComments.re
Expand Up @@ -711,3 +711,26 @@ let r = {
fieldOne: (identifier : string), /*eol1*/
fieldTwo: (identifier : string), /* eol2 with trailing comma */
};

/** doc comment */
[@bs.send]
external url : t => string = "";

/**
* Short multiline doc comment
*/
[@bs.send]
external url : t => string = "";

/** Longer doc comment before an attribute on an external. */
[@bs.send]
external url : t => string = "";

/* normal comment */
[@bs.send] external url : t => string = "";

/** doc type */
type q = {a: int, b: string};

/** doc let */
let letter : q = {a: 42, b: "answer"};
15 changes: 12 additions & 3 deletions src/reason-parser/reason_pprint_ast.ml
Expand Up @@ -5780,7 +5780,8 @@ let printer = object(self:'self)
| Pctf_extension e -> self#item_extension e

(*
[@@bs.val] [@@bs.module "react-dom"] (* formattedAttrs *)
/** doc comment */ (* formattedDocs *)
[@bs.val] [@bs.module "react-dom"] (* formattedAttrs *)
external render : reactElement => element => unit = (* frstHalf *)
"render"; (* sndHalf *)

Expand All @@ -5789,6 +5790,7 @@ let printer = object(self:'self)
* combine that label with '=' in a list
* consider the part after the '=' as a list
* combine both parts as a label
* format the doc comment with a ~postSpace:true (inline, not inline) list
* format the attributes with a ~postSpace:true (inline, inline) list
* format everything together in a ~postSpace:true (inline, inline) list
for nicer breaking
Expand All @@ -5805,9 +5807,16 @@ let printer = object(self:'self)
match vd.pval_attributes with
| [] -> primDecl
| attrs ->
let attrs = List.map (fun x -> self#item_attribute x) attrs in
let {stdAttrs; docAttrs} = partitionAttributes ~partDoc:true attrs in
let docs = List.map self#item_attribute docAttrs in
let formattedDocs = makeList ~postSpace:true docs in
let attrs = List.map self#item_attribute stdAttrs in
let formattedAttrs = makeSpacedBreakableInlineList attrs in
makeSpacedBreakableInlineList [formattedAttrs; primDecl]
let layouts = match (docAttrs, stdAttrs) with
| ([], _) -> [formattedAttrs; primDecl]
| (_, []) -> [formattedDocs; primDecl]
| _ -> [formattedDocs; formattedAttrs; primDecl] in
makeSpacedBreakableInlineList layouts

method class_instance_type x =
match x.pcty_desc with
Expand Down