Skip to content

sync changes to outcome printer #281

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

Merged
merged 1 commit into from
Jun 30, 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
16 changes: 12 additions & 4 deletions analysis/src/vendor/res_outcome_printer/res_outcome_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ let printPolyVarIdent txt =
| [], [] -> Doc.nil
| labels, types ->
let i = ref 0 in
let package = Doc.join ~sep:Doc.line (List.map2 (fun lbl typ ->
let package = Doc.join ~sep:Doc.line ((List.map2 [@doesNotRaise]) (fun lbl typ ->
Doc.concat [
Doc.text (if i.contents > 0 then "and " else "with ");
Doc.text lbl;
Expand Down Expand Up @@ -376,13 +376,21 @@ let printPolyVarIdent txt =
let (typArgs, typ) = collectArrowArgs typ [] in
let args = Doc.join ~sep:(Doc.concat [Doc.comma; Doc.line]) (
List.map (fun (lbl, typ) ->
if lbl = "" then
let lblLen = String.length lbl in
if lblLen = 0 then
printOutTypeDoc typ
else
let (lbl, optionalIndicator) =
(* the ocaml compiler hardcodes the optional label inside the string of the label in printtyp.ml *)
match String.unsafe_get lbl 0 with
| '?' -> ((String.sub [@doesNotRaise]) lbl 1 (lblLen - 1) , Doc.text "=?")
| _ -> (lbl, Doc.nil)
in
Doc.group (
Doc.concat [
Doc.text ("~" ^ lbl ^ ": ");
printOutTypeDoc typ
printOutTypeDoc typ;
optionalIndicator
]
)
) typArgs
Expand Down Expand Up @@ -468,7 +476,7 @@ let printPolyVarIdent txt =
and printObjectFields fields rest =
let dots = match rest with
| Some non_gen -> Doc.text ((if non_gen then "_" else "") ^ "..")
| None -> Doc.nil
| None -> if fields = [] then Doc.dot else Doc.nil
in
Doc.group (
Doc.concat [
Expand Down
2 changes: 1 addition & 1 deletion analysis/tests/src/expected/Div.res.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Hover tests/src/Div.res 1:10
{"contents": "```rescript\n(\n string,\n ~?props: ReactDOMRe.domProps,\n array<React.element>,\n) => React.element\n```"}
{"contents": "```rescript\n(\n string,\n ~props: ReactDOMRe.domProps=?,\n array<React.element>,\n) => React.element\n```"}

Complete tests/src/Div.res 3:3
[{
Expand Down
2 changes: 1 addition & 1 deletion analysis/tests/src/expected/Jsx.resi.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Hover tests/src/Jsx.resi 1:4
{"contents": "```rescript\n(~first: string, ~?key: string, unit) => {\"first\": string}\n```"}
{"contents": "```rescript\n(~first: string, ~key: string=?, unit) => {\"first\": string}\n```"}

Hover tests/src/Jsx.resi 4:4
{"contents": "```rescript\nint\n```"}
Expand Down