diff --git a/analysis/tests/src/expected/Hover.res.txt b/analysis/tests/src/expected/Hover.res.txt index 0b932cbc5..2596ca073 100644 --- a/analysis/tests/src/expected/Hover.res.txt +++ b/analysis/tests/src/expected/Hover.res.txt @@ -159,7 +159,7 @@ Completable: Cpath Value[y2].content."" }] Hover src/Hover.res 197:4 -{"contents": "```rescript\nCompV4.props => React.element\n```\n\n\n```\n \n```\n```rescript\ntype CompV4.props<'n, 's> = {?n: 'n, s: 's}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C190%2C2%5D)\n\n---\n\n\n\n```\n \n```\n```rescript\ntype React.element\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C0%2C0%5D)\n\n---\n"} +{"contents": "```rescript\nCompV4.props => React.element\n```\n\n\n```\n \n```\n```rescript\ntype CompV4.props<'n, 's> = {n?: 'n, s: 's}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C190%2C2%5D)\n\n---\n\n\n\n```\n \n```\n```rescript\ntype React.element\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C0%2C0%5D)\n\n---\n"} Hover src/Hover.res 202:16 {"contents": "```rescript\nuseR\n```\n\n\n```\n \n```\n```rescript\ntype useR = {x: int, y: list>>}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C200%2C0%5D)\n\n---\n\n\n\n```\n \n```\n```rescript\ntype r<'a> = {i: 'a, f: float}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C101%2C0%5D)\n\n---\n"} diff --git a/analysis/vendor/res_outcome_printer/res_core.ml b/analysis/vendor/res_outcome_printer/res_core.ml index 8547e4f3d..ba0e4d4de 100644 --- a/analysis/vendor/res_outcome_printer/res_core.ml +++ b/analysis/vendor/res_outcome_printer/res_core.ml @@ -2691,13 +2691,9 @@ and parseBracedOrRecordExpr p = Parser.expect Lbrace p; match p.Parser.token with | Rbrace -> - Parser.err p (Diagnostics.unexpected Rbrace p.breadcrumbs); Parser.next p; let loc = mkLoc startPos p.prevEndPos in - let braces = makeBracesAttr loc in - Ast_helper.Exp.construct ~attrs:[braces] ~loc - (Location.mkloc (Longident.Lident "()") loc) - None + Ast_helper.Exp.record ~loc [] None | DotDotDot -> (* beginning of record spread, parse record *) Parser.next p; @@ -4286,6 +4282,7 @@ and parseFieldDeclaration p = match p.token with | _ -> parseLident p in + let optional = parseOptionalLabel p in let name = Location.mkloc lident loc in let typ = match p.Parser.token with @@ -4296,7 +4293,7 @@ and parseFieldDeclaration p = Ast_helper.Typ.constr ~loc:name.loc {name with txt = Lident name.txt} [] in let loc = mkLoc startPos typ.ptyp_loc.loc_end in - Ast_helper.Type.field ~attrs ~loc ~mut name typ + (optional, Ast_helper.Type.field ~attrs ~loc ~mut name typ) and parseFieldDeclarationRegion p = let startPos = p.Parser.startPos in @@ -4488,7 +4485,10 @@ and parseConstrDeclArgs p = ~closing:Rbrace ~f:parseFieldDeclarationRegion p | attrs -> let first = - let field = parseFieldDeclaration p in + let optional, field = parseFieldDeclaration p in + let attrs = + if optional then optionalAttr :: attrs else attrs + in Parser.expect Comma p; {field with Parsetree.pld_attributes = attrs} in @@ -4885,13 +4885,15 @@ and parseRecordOrObjectDecl p = | _ -> Parser.leaveBreadcrumb p Grammar.RecordDecl; let fields = + (* XXX *) match attrs with | [] -> parseCommaDelimitedRegion ~grammar:Grammar.FieldDeclarations ~closing:Rbrace ~f:parseFieldDeclarationRegion p | attr :: _ as attrs -> let first = - let field = parseFieldDeclaration p in + let optional, field = parseFieldDeclaration p in + let attrs = if optional then optionalAttr :: attrs else attrs in Parser.optional p Comma |> ignore; { field with @@ -4907,13 +4909,6 @@ and parseRecordOrObjectDecl p = :: parseCommaDelimitedRegion ~grammar:Grammar.FieldDeclarations ~closing:Rbrace ~f:parseFieldDeclarationRegion p in - let () = - match fields with - | [] -> - Parser.err ~startPos p - (Diagnostics.message "A record needs at least one field") - | _ -> () - in Parser.expect Rbrace p; Parser.eatBreadcrumb p; (None, Asttypes.Public, Parsetree.Ptype_record fields)) diff --git a/analysis/vendor/res_outcome_printer/res_outcome_printer.ml b/analysis/vendor/res_outcome_printer/res_outcome_printer.ml index ec69e9e02..97560bf22 100644 --- a/analysis/vendor/res_outcome_printer/res_outcome_printer.ml +++ b/analysis/vendor/res_outcome_printer/res_outcome_printer.ml @@ -526,9 +526,9 @@ and printRecordDeclRowDoc (name, mut, opt, arg) = Doc.group (Doc.concat [ - (if opt then Doc.text "?" else Doc.nil); (if mut then Doc.text "mutable " else Doc.nil); printIdentLike ~allowUident:false name; + (if opt then Doc.text "?" else Doc.nil); Doc.text ": "; printOutTypeDoc arg; ]) @@ -563,7 +563,8 @@ let printTypeParameterDoc (typ, (co, cn)) = (if typ = "_" then Doc.text "_" else Doc.text ("'" ^ typ)); ] -let rec printOutSigItemDoc ?(printNameAsIs=false) (outSigItem : Outcometree.out_sig_item) = +let rec printOutSigItemDoc ?(printNameAsIs = false) + (outSigItem : Outcometree.out_sig_item) = match outSigItem with | Osig_class _ | Osig_class_type _ -> Doc.nil | Osig_ellipsis -> Doc.dotdotdot @@ -728,7 +729,8 @@ let rec printOutSigItemDoc ?(printNameAsIs=false) (outSigItem : Outcometree.out_ [ attrs; kw; - if printNameAsIs then Doc.text outTypeDecl.otype_name else printIdentLike ~allowUident:false outTypeDecl.otype_name; + (if printNameAsIs then Doc.text outTypeDecl.otype_name + else printIdentLike ~allowUident:false outTypeDecl.otype_name); typeParams; kind; ]); @@ -823,7 +825,7 @@ and printOutSignatureDoc (signature : Outcometree.out_sig_item list) = let doc = printOutTypeExtensionDoc te in loop items (doc :: acc) | item :: items -> - let doc = printOutSigItemDoc item in + let doc = printOutSigItemDoc ~printNameAsIs:false item in loop items (doc :: acc) in match loop signature [] with diff --git a/analysis/vendor/res_outcome_printer/res_outcome_printer.mli b/analysis/vendor/res_outcome_printer/res_outcome_printer.mli index 1b498dfa2..d3ee60aa4 100644 --- a/analysis/vendor/res_outcome_printer/res_outcome_printer.mli +++ b/analysis/vendor/res_outcome_printer/res_outcome_printer.mli @@ -13,4 +13,6 @@ val setup : unit lazy_t [@@live] (* Needed for e.g. the playground to print typedtree data *) val printOutTypeDoc : Outcometree.out_type -> Res_doc.t [@@live] -val printOutSigItemDoc : ?printNameAsIs: bool -> Outcometree.out_sig_item -> Res_doc.t [@@live] +val printOutSigItemDoc : + ?printNameAsIs:bool -> Outcometree.out_sig_item -> Res_doc.t + [@@live] diff --git a/analysis/vendor/res_outcome_printer/res_printer.ml b/analysis/vendor/res_outcome_printer/res_printer.ml index c1d947d4a..b6f2d9ddc 100644 --- a/analysis/vendor/res_outcome_printer/res_printer.ml +++ b/analysis/vendor/res_outcome_printer/res_printer.ml @@ -3651,13 +3651,16 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl = [(Nolabel, lhs); (Nolabel, rhs)] ) when not (ParsetreeViewer.isBinaryExpression lhs - || ParsetreeViewer.isBinaryExpression rhs) -> + || ParsetreeViewer.isBinaryExpression rhs + || printAttributes ~customLayout expr.pexp_attributes cmtTbl + <> Doc.nil) -> let lhsHasCommentBelow = hasCommentBelow cmtTbl lhs.pexp_loc in let lhsDoc = printOperand ~isLhs:true lhs op in let rhsDoc = printOperand ~isLhs:false rhs op in Doc.group (Doc.concat [ + printAttributes ~customLayout expr.pexp_attributes cmtTbl; lhsDoc; (match (lhsHasCommentBelow, op) with | true, "|." -> Doc.concat [Doc.softLine; Doc.text "->"]