Skip to content

Commit eef0e3b

Browse files
committed
sync changes to outcome printer
1 parent 169cdfd commit eef0e3b

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

analysis/src/vendor/res_outcome_printer/res_outcome_printer.ml

+12-4
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ let printPolyVarIdent txt =
348348
| [], [] -> Doc.nil
349349
| labels, types ->
350350
let i = ref 0 in
351-
let package = Doc.join ~sep:Doc.line (List.map2 (fun lbl typ ->
351+
let package = Doc.join ~sep:Doc.line ((List.map2 [@doesNotRaise]) (fun lbl typ ->
352352
Doc.concat [
353353
Doc.text (if i.contents > 0 then "and " else "with ");
354354
Doc.text lbl;
@@ -376,13 +376,21 @@ let printPolyVarIdent txt =
376376
let (typArgs, typ) = collectArrowArgs typ [] in
377377
let args = Doc.join ~sep:(Doc.concat [Doc.comma; Doc.line]) (
378378
List.map (fun (lbl, typ) ->
379-
if lbl = "" then
379+
let lblLen = String.length lbl in
380+
if lblLen = 0 then
380381
printOutTypeDoc typ
381382
else
383+
let (lbl, optionalIndicator) =
384+
(* the ocaml compiler hardcodes the optional label inside the string of the label in printtyp.ml *)
385+
match String.unsafe_get lbl 0 with
386+
| '?' -> ((String.sub [@doesNotRaise]) lbl 1 (lblLen - 1) , Doc.text "=?")
387+
| _ -> (lbl, Doc.nil)
388+
in
382389
Doc.group (
383390
Doc.concat [
384391
Doc.text ("~" ^ lbl ^ ": ");
385-
printOutTypeDoc typ
392+
printOutTypeDoc typ;
393+
optionalIndicator
386394
]
387395
)
388396
) typArgs
@@ -468,7 +476,7 @@ let printPolyVarIdent txt =
468476
and printObjectFields fields rest =
469477
let dots = match rest with
470478
| Some non_gen -> Doc.text ((if non_gen then "_" else "") ^ "..")
471-
| None -> Doc.nil
479+
| None -> if fields = [] then Doc.dot else Doc.nil
472480
in
473481
Doc.group (
474482
Doc.concat [

analysis/tests/src/expected/Div.res.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Hover tests/src/Div.res 1:10
2-
{"contents": "```rescript\n(\n string,\n ~?props: ReactDOMRe.domProps,\n array<React.element>,\n) => React.element\n```"}
2+
{"contents": "```rescript\n(\n string,\n ~props: ReactDOMRe.domProps=?,\n array<React.element>,\n) => React.element\n```"}
33

44
Complete tests/src/Div.res 3:3
55
[{

analysis/tests/src/expected/Jsx.resi.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Hover tests/src/Jsx.resi 1:4
2-
{"contents": "```rescript\n(~first: string, ~?key: string, unit) => {\"first\": string}\n```"}
2+
{"contents": "```rescript\n(~first: string, ~key: string=?, unit) => {\"first\": string}\n```"}
33

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

0 commit comments

Comments
 (0)